Sha256: 985b53360dc309b28aa134bb27feb7be03016f7769e2aac873bcbf80227342e4

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

# @see http://nakajima.github.com/rack-flash
# @example
#   use Rack::Flash
#   message["notice"]
#   flash["notice"]
#   OR
#   use Rack::Flash, accessorize: [:notice, :error]
#   message.notice
#   flash.notice
module Rango
  module RackFlashMixin
    # @since 0.2.4
    # NOTE: it's important to include this mixin after ImplicitRendering mixin
    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

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rango-0.2.6 lib/rango/mixins/rack-flash.rb
rango-0.2.5.1 lib/rango/mixins/rack-flash.rb
rango-0.2.4.1 lib/rango/mixins/rack-flash.rb