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 Method Summary collapse

Constructor Details

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

Returns a new instance of FlashHash.



37
38
39
40
41
42
43
# File 'lib/rack/flash.rb', line 37

def initialize(store, opts={})
  raise Rack::Flash::SessionUnavailable \
    .new('Rack::Flash depends on session middleware.') unless store

  @opts = opts
  @store = store
end

Instance Method Details

#[](key) ⇒ Object

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



47
48
49
50
# File 'lib/rack/flash.rb', line 47

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

#[]=(key, val) ⇒ Object

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



53
54
55
56
# File 'lib/rack/flash.rb', line 53

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.



65
66
67
# File 'lib/rack/flash.rb', line 65

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

#sweep!Object

Remove flagged entries from flash session, clear flagged list.



59
60
61
# File 'lib/rack/flash.rb', line 59

def sweep!
  values.clear
end

#to_sObject

Human readable for logging.



70
71
72
# File 'lib/rack/flash.rb', line 70

def to_s
  values.inspect
end