Implements bracket accessors for storing and retrieving flash entries.
# 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
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
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
Mark existing entries to allow for sweeping.
# File lib/rack/flash.rb, line 79 def flag! @flagged = values.keys end
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
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
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
Generated with the Darkfish Rdoc Generator 2.