Module: EmberRailsFlash

Defined in:
lib/ember-rails-flash/version.rb,
lib/ember-rails-flash/rails/engine.rb,
lib/ember-rails-flash/flash_in_header.rb,
lib/ember-rails-flash/enable_flash_responder.rb

Defined Under Namespace

Modules: FlashInHeader, Rails

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.enable_flash_responder(format = 'json') ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ember-rails-flash/enable_flash_responder.rb', line 2

def self.enable_flash_responder(format='json')
  if defined?(Responders::FlashResponder)
    to_meth = :"to_#{format}"
    unless Responders::FlashResponder.public_instance_methods.include?(to_meth)
      Responders::FlashResponder.class_eval <<-EORUBY
        def #{to_meth}
          set_flash_message! if set_flash_message?
          defined?(super) ? super : to_format
        end
      EORUBY
    else
      Rails.logger.debug { "Responders::FlashResponder##{to_meth} is already defined" }
    end
  else
    Rails.logger.debug { "cannot find Responders::FlashResponder to enable flash on #{format}" }
  end
end