Class: Crystal::Flash

Inherits:
OpenObject
  • Object
show all
Defined in:
lib/crystal/html/flash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Flash.



7
8
9
10
11
# File 'lib/crystal/html/flash.rb', line 7

def initialize format, previous_messages = {}
  self.current_messages, self.previous_messages = {}, previous_messages
  self.ajax_mode = format == 'js'
  self.force_keeping_mode = false
end

Instance Attribute Details

#ajax_modeObject

Returns the value of attribute ajax_mode.



5
6
7
# File 'lib/crystal/html/flash.rb', line 5

def ajax_mode
  @ajax_mode
end

#current_messagesObject

Returns the value of attribute current_messages.



3
4
5
# File 'lib/crystal/html/flash.rb', line 3

def current_messages
  @current_messages
end

#force_keeping_modeObject

Returns the value of attribute force_keeping_mode.



5
6
7
# File 'lib/crystal/html/flash.rb', line 5

def force_keeping_mode
  @force_keeping_mode
end

#previous_messagesObject

Returns the value of attribute previous_messages.



3
4
5
# File 'lib/crystal/html/flash.rb', line 3

def previous_messages
  @previous_messages
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/crystal/html/flash.rb', line 13

def [] key
  key = key.to_s
  
  if ajax_mode and !force_keeping_mode
    current_messages[key] || previous_messages[key]
  else
    previous_messages[key]
  end
end

#[]=(key, value) ⇒ Object



23
24
25
# File 'lib/crystal/html/flash.rb', line 23

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

#force_keeping_mode!Object



27
28
29
# File 'lib/crystal/html/flash.rb', line 27

def force_keeping_mode!
  self.force_keeping_mode = true
end

#messages_for_next_requestObject



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

def messages_for_next_request
  if ajax_mode and !force_keeping_mode
    {}
  else
    current_messages
  end
end