Class: TinyRackFlash::FlashHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/tiny_rack_flash.rb

Overview

This FlashHash implmentation is taken from Stephen Eley’s work at github.com/SFEley/sinatra-flash/blob/master/lib/sinatra/flash/hash.rb which in turn is heavily inspired by ActionDispatch::Flash::FlashHash at github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/flash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ FlashHash

Returns a new instance of FlashHash.



15
16
17
18
19
# File 'lib/tiny_rack_flash.rb', line 15

def initialize(session)
  @now = session || Hash.new
  @next = Hash.new
  super(@now)
end

Instance Attribute Details

#nextObject (readonly)

Returns the value of attribute next.



14
15
16
# File 'lib/tiny_rack_flash.rb', line 14

def next
  @next
end

#nowObject (readonly)

Returns the value of attribute now.



14
15
16
# File 'lib/tiny_rack_flash.rb', line 14

def now
  @now
end

Instance Method Details

#[]=(key, value) ⇒ Object



21
22
23
# File 'lib/tiny_rack_flash.rb', line 21

def []=(key, value)
  self.next[key] = value
end

#discard(key = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/tiny_rack_flash.rb', line 39

def discard(key=nil)
  if key
    @next.delete(key)
  else
    @next = Hash.new
  end
end

#keep(key = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tiny_rack_flash.rb', line 31

def keep(key=nil)
  if key
    @next[key] = @now[key]
  else
    @next.merge!(@now)
  end
end

#sweepObject



25
26
27
28
29
# File 'lib/tiny_rack_flash.rb', line 25

def sweep
  @now.replace(@next)
  @next = Hash.new
  @now
end