Class: Rad::Html::Flash

Inherits:
OpenObject
  • Object
show all
Defined in:
lib/rad/html/_flash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, previous_messages = {}) ⇒ Flash

Returns a new instance of Flash.



4
5
6
7
# File 'lib/rad/html/_flash.rb', line 4

def initialize format, previous_messages = {}
  self.current_messages, self.previous_messages = {}, previous_messages
  @keep = false
end

Instance Attribute Details

#current_messagesObject

Returns the value of attribute current_messages.



2
3
4
# File 'lib/rad/html/_flash.rb', line 2

def current_messages
  @current_messages
end

#previous_messagesObject

Returns the value of attribute previous_messages.



2
3
4
# File 'lib/rad/html/_flash.rb', line 2

def previous_messages
  @previous_messages
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rad/html/_flash.rb', line 9

def [] key
  key = key.to_s

  if keep?
    previous_messages[key]
  else
    current_messages[key] || previous_messages[key]
  end
end

#[]=(key, value) ⇒ Object



19
20
21
# File 'lib/rad/html/_flash.rb', line 19

def []= key, value
  current_messages[key.to_s] = value.to_s
end

#keep!Object



23
24
25
26
# File 'lib/rad/html/_flash.rb', line 23

def keep!
  @keep = true
  self
end

#keep?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rad/html/_flash.rb', line 28

def keep?
  !!@keep
end

#messages_for_next_requestObject



32
33
34
35
36
37
38
# File 'lib/rad/html/_flash.rb', line 32

def messages_for_next_request
  if keep?
    current_messages
  else
    {}
  end
end