Module: FlashMessenger::Helper

Included in:
ViewHelper
Defined in:
lib/flash-messenger/helper.rb

Instance Method Summary collapse

Instance Method Details

#flash_alert(message, options = nil) ⇒ Object



13
14
15
# File 'lib/flash-messenger/helper.rb', line 13

def flash_alert(message, options = nil)
  push_flash(message, options, 'alert')
end

#flash_error(message, options = nil) ⇒ Object



17
18
19
# File 'lib/flash-messenger/helper.rb', line 17

def flash_error(message, options = nil)
  push_flash(message, options, 'error')
end

#flash_message(message, options = nil) ⇒ Object



5
6
7
# File 'lib/flash-messenger/helper.rb', line 5

def flash_message(message, options = nil)
  push_flash(message, options)
end

#flash_messengerObject



28
29
30
# File 'lib/flash-messenger/helper.rb', line 28

def flash_messenger
  RequestStore.store[:flash_messenger] ||= []
end

#flash_model_error(errors, options = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/flash-messenger/helper.rb', line 21

def flash_model_error(errors, options = nil)
  errors = errors.errors if errors.is_a? ActiveRecord::Base
  errors.full_messages.to_a.each do |message|
    push_flash(message, options, 'error')
  end
end

#flash_notice(message, options = nil) ⇒ Object



9
10
11
# File 'lib/flash-messenger/helper.rb', line 9

def flash_notice(message, options = nil)
  push_flash(message, options, 'notice')
end

#push_flash(message, options, method = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/flash-messenger/helper.rb', line 32

def push_flash(message, options, method = nil)
  options = options.nil? ? options : options.clone
  if method.nil?
    if options.nil?
      job = [message]
    else
      job = [message, options]
    end
  else
    job = [message, options, method]
  end
  flash_messenger << job
end