Class: Syntropy::Session::Flash

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/request/session.rb

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Flash

Returns a new instance of Flash.



61
62
63
64
65
66
67
68
# File 'lib/syntropy/request/session.rb', line 61

def initialize(session)
  @session = session
  @current_flash_data = @session['_flash']
  @session.delete('_flash') if @current_flash_data
  @current_flash_data ||= {}
  @future_flash_data = {}
  @now_flash_data = NowFlash.new
end

Instance Method Details

#[](key) ⇒ Object



70
71
72
73
# File 'lib/syntropy/request/session.rb', line 70

def [](key)
  key = key.to_s
  @now_flash_data[key] || @current_flash_data[key]
end

#[]=(key, value) ⇒ Object



75
76
77
78
79
# File 'lib/syntropy/request/session.rb', line 75

def []=(key, value)
  key = key.to_s
  @future_flash_data[key] = value
  @session['_flash'] = @future_flash_data
end

#each(&block) ⇒ Object



81
82
83
84
# File 'lib/syntropy/request/session.rb', line 81

def each(&block)
  @now_flash_data.each { |k, v| block.(k.to_sym, v) }
  @current_flash_data.each_pair { |k, v| block.(k.to_sym, v) }
end

#keepObject



86
87
88
89
# File 'lib/syntropy/request/session.rb', line 86

def keep
  @future_flash_data = @current_flash_data.merge!(@future_flash_data)
  @session['_flash'] = @future_flash_data
end

#nowObject



91
92
93
# File 'lib/syntropy/request/session.rb', line 91

def now
  @now_flash_data
end