Class: Ramaze::Session::Flash

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ramaze/current/session/flash.rb

Overview

The purpose of this class is to act as a unifier of the previous and current flash.

Flash means pairs of keys and values that are held only over one request/response cycle. So you can assign a key/value in the current session and retrieve it in the current and following request.

Please see the FlashHelper for details on the usage as you won’t need to touch this class at all.

Instance Method Summary collapse

Constructor Details

#initialize(sess) ⇒ Flash

Returns a new instance of Flash.



15
16
17
# File 'lib/ramaze/current/session/flash.rb', line 15

def initialize sess
  @session = sess
end

Instance Method Details

#[](key) ⇒ Object

flash in your Controller



41
42
43
# File 'lib/ramaze/current/session/flash.rb', line 41

def [](key)
  combined[key]
end

#[]=(key, value) ⇒ Object

flash = value in your Controller



46
47
48
49
50
# File 'lib/ramaze/current/session/flash.rb', line 46

def []=(key, value)
  prev = session[:FLASH] || {}
  prev[key] = value
  session[:FLASH] = prev
end

#combinedObject

combined key/value pairs of previous and current current keys overshadow the old ones.



36
37
38
# File 'lib/ramaze/current/session/flash.rb', line 36

def combined
  previous.merge(current)
end

#currentObject

the current session



30
31
32
# File 'lib/ramaze/current/session/flash.rb', line 30

def current
  session[:FLASH] ||= {}
end

#delete(key) ⇒ Object

Delete a key



60
61
62
# File 'lib/ramaze/current/session/flash.rb', line 60

def delete(key)
  current.delete(key)
end

#each(&block) ⇒ Object

iterate over the combined session



20
21
22
# File 'lib/ramaze/current/session/flash.rb', line 20

def each(&block)
  combined.each(&block)
end

#empty?Boolean

check if combined is empty

Returns:

  • (Boolean)


66
67
68
# File 'lib/ramaze/current/session/flash.rb', line 66

def empty?
  combined.empty?
end

#inspectObject

Inspects the combined SessionFlash



54
55
56
# File 'lib/ramaze/current/session/flash.rb', line 54

def inspect
  combined.inspect
end

#previousObject

the current session



25
26
27
# File 'lib/ramaze/current/session/flash.rb', line 25

def previous
  session[:FLASH_PREVIOUS] || {}
end