Parent

Class/Module Index [+]

Quicksearch

Rack::Flash::FlashHash

Implements bracket accessors for storing and retrieving flash entries.

Attributes

flagged[R]

Public Class Methods

new(store, opts={}) click to toggle source
# File lib/rack/flash.rb, line 39
def initialize(store, opts={})
  raise Rack::Flash::SessionUnavailable            .new('Rack::Flash depends on session middleware.') unless store

  @opts = opts
  @store = store

  if accessors = @opts[:accessorize]
    accessors.each { |opt| def_accessor(opt) }
  end
end

Public Instance Methods

[](key) click to toggle source

Remove an entry from the session and return its value. Cache result in the instance cache.

# File lib/rack/flash.rb, line 53
def [](key)
  key = key.to_sym
  cache[key] ||= values.delete(key)
end
[]=(key,val) click to toggle source

Store the entry in the session, updating the instance cache as well.

# File lib/rack/flash.rb, line 59
def []=(key,val)
  key = key.to_sym
  cache[key] = values[key] = val
end
flag!() click to toggle source

Mark existing entries to allow for sweeping.

# File lib/rack/flash.rb, line 79
def flag!
  @flagged = values.keys
end
has?(key) click to toggle source

Checks for the presence of a flash entry without retrieving or removing it from the cache or store.

# File lib/rack/flash.rb, line 73
def has?(key)
  [cache, values].any? { |store| store.keys.include?(key.to_sym) }
end
Also aliased as: include?
include?(key) click to toggle source
Alias for: has?
inspect() click to toggle source

Hide the underlying :__FLASH__ session key and only expose values stored in the flash.

# File lib/rack/flash.rb, line 91
def inspect
  '#<FlashHash @values=%s @cache=%s>' % [values.inspect, cache.inspect]
end
now() click to toggle source

Store a flash entry for only the current request, swept regardless of whether or not it was actually accessed. Useful for AJAX requests, where you want a flash message, even though you’re response isn’t redirecting.

# File lib/rack/flash.rb, line 67
def now
  cache
end
sweep!() click to toggle source

Remove flagged entries from flash session, clear flagged list.

# File lib/rack/flash.rb, line 84
def sweep!
  Array(flagged).each { |key| values.delete(key) }
  flagged.clear
end
to_s() click to toggle source

Human readable for logging.

# File lib/rack/flash.rb, line 96
def to_s
  values.inspect
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.