module FlushingFlash::ActionControllerMethods::InstanceMethods

Public Instance Methods

pull_flash(target=:default) click to toggle source
# File lib/flushing-flash/action_controller_methods.rb, line 32
def pull_flash(target=:default)
  @pulled_flashes ||= {}
  return @pulled_flashes[target] if @pulled_flashes[target]
  
  pulled_flashes = flash[target] || []
  flash.delete(target)
  
  if pulled_flashes.is_a?(Array)
    @pulled_flashes[target] = pulled_flashes
  else
    @pulled_flashes[target] = [to_flushing_flash_message(target, pulled_flashes)]
  end

  @pulled_flashes[target]
end
push_flash(message_type, *args) click to toggle source
# File lib/flushing-flash/action_controller_methods.rb, line 13
def push_flash(message_type, *args)
  opts = args.extract_options!

  i18n_options = opts.delete(:i18n_options)
  target = opts.delete(:target) || :default

  flash_content = case args[0].class.name
  when String.name
    args[0]
  when Symbol.name
    I18n.t("flashes.#{args[0]}.#{message_type}", i18n_options)
  else
    I18n.t("flashes.#{self.class.name.gsub(/Controller$/, "").underscore.gsub(/\//, ".")}.#{action_name.underscore}.#{message_type}", i18n_options)
  end

  flash[target] ||= []
  flash[target] << to_flushing_flash_message(message_type, flash_content)
end
to_flushing_flash_message(message_type, flash_content) click to toggle source
# File lib/flushing-flash/action_controller_methods.rb, line 48
def to_flushing_flash_message(message_type, flash_content)
  { message_type: message_type, content: flash_content }
end