Module: Rango::RackFlashMixin

Defined in:
lib/rango/mixins/rack-flash.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object

NOTE: it’s important to include this mixin after ImplicitRendering mixin

Since:

  • 0.2.4



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rango/mixins/rack-flash.rb', line 16

def self.included(controller)
  if controller.method_defined?(:context)
    Rango.logger.debug("Extending context by message")
    controller.class_eval do
      include Module.new {
        def context
          @context ||= super.merge!(message: self.message)
        end
      }
    end
  else
    Rango.logger.warn("Context method isn't defined")
  end
end

Instance Method Details

#messageObject Also known as: flash



31
32
33
34
35
# File 'lib/rango/mixins/rack-flash.rb', line 31

def message
  @message ||= begin
    request.env["x-rack.flash"]
  end
end

#redirect(uri, status = 303, options = Hash.new, &block) ⇒ Object



38
39
40
41
42
# File 'lib/rango/mixins/rack-flash.rb', line 38

def redirect(uri, status = 303, options = Hash.new, &block)
  status, options = 303, status if status.is_a?(Hash)
  options.each { |type, message| flash[type] = message }
  super(uri, status)
end