Class: Lux::Response::Flash

Inherits:
Object show all
Defined in:
lib/lux/response/lib/flash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = nil) ⇒ Flash

Returns a new instance of Flash.



18
19
20
# File 'lib/lux/response/lib/flash.rb', line 18

def initialize h=nil
  @msg = h || {}
end

Class Method Details

.add_type(name) ⇒ Object

flash.info ‘messsage …’ flash.info = ‘messsage …’



7
8
9
10
# File 'lib/lux/response/lib/flash.rb', line 7

def self.add_type name
  define_method(name) { |message| add name, message }
  eval "alias #{name}= #{name}"
end

Instance Method Details

#clearObject



22
23
24
# File 'lib/lux/response/lib/flash.rb', line 22

def clear
  to_h.tap { @msg = {} }
end

#clear_for_jsObject

clears white space, replaces quotes



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

def clear_for_js
  {}.tap do |msg|
    clear.each do |k, v|
      msg[k] = v.join(', ').gsub(/\s+/, ' ')
    end
  end
end

#to_hObject



26
27
28
# File 'lib/lux/response/lib/flash.rb', line 26

def to_h
  @msg
end