Class: Booth::Userland::ExtractFlashMessages

Inherits:
Object
  • Object
show all
Includes:
Logging, Calls
Defined in:
lib/booth/userland/extract_flash_messages.rb

Instance Method Summary collapse

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/booth/userland/extract_flash_messages.rb', line 17

def call
  check_arguments!
  return unless from.respond_to?(:public_message)
  return if from.public_message.blank?

  if from.success?
    log { "Saving flash notice: #{from.public_message}" }
    to[:notice] = from.public_message
  else
    log { "Saving flash alert: #{from.public_message}" }
    to[:alert] = from.public_message
  end

  nil
end

#check_arguments!Object

Raises:



33
34
35
36
37
38
39
# File 'lib/booth/userland/extract_flash_messages.rb', line 33

def check_arguments!
  raise(ArgumentError, 'You can only extract flash messages from something that is not nil') if from.nil?

  return if to.respond_to?(:notice=)

  raise ArgumentError, "Please pass in `to: flash` for public flash messages not #{to.inspect}"
end