Class: Booth::Userland::ExtractFlashMessages

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

Instance Method Summary collapse

Methods included from MethodObject

included

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/booth/userland/extract_flash_messages.rb', line 10

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

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

  nil
end

#check_arguments!Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/booth/userland/extract_flash_messages.rb', line 26

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