Class: Rack::Flash::FlashHash

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/flash.rb

Overview

Implements bracket accessors for storing and retrieving flash entries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, opts = {}) ⇒ FlashHash

Returns a new instance of FlashHash.



39
40
41
42
43
44
45
# 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
end

Instance Attribute Details

#flaggedObject (readonly)

Returns the value of attribute flagged.



37
38
39
# File 'lib/rack/flash.rb', line 37

def flagged
  @flagged
end

Instance Method Details

#[](key) ⇒ Object

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



49
50
51
52
# File 'lib/rack/flash.rb', line 49

def [](key)
  key = key.to_sym
  values[key]
end

#[]=(key, val) ⇒ Object

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



55
56
57
58
# File 'lib/rack/flash.rb', line 55

def []=(key,val)
  key = key.to_sym
  values[key] = val
end

#inspectObject

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



67
68
69
# File 'lib/rack/flash.rb', line 67

def inspect
  '#<FlashHash @values=%s @cache=%s>' % [values.inspect, cache.inspect]
end

#sweep!Object

Remove flagged entries from flash session, clear flagged list.



61
62
63
# File 'lib/rack/flash.rb', line 61

def sweep!
  values.clear
end

#to_sObject

Human readable for logging.



72
73
74
# File 'lib/rack/flash.rb', line 72

def to_s
  values.inspect
end