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.



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

def initialize h = nil
  @msg = (h || {}).to_hwia
end

Class Method Details

.add_type(name) ⇒ Object

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



10
11
12
13
# File 'lib/lux/response/lib/flash.rb', line 10

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

Instance Method Details

#clearObject



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

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

#clear_for_jsObject

clears white space, replaces quotes



42
43
44
45
46
47
48
# File 'lib/lux/response/lib/flash.rb', line 42

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

#empty?Boolean

Returns:



33
34
35
# File 'lib/lux/response/lib/flash.rb', line 33

def empty?
  !present?
end

#present?Boolean

Returns:



29
30
31
# File 'lib/lux/response/lib/flash.rb', line 29

def present?
  @msg.keys.first
end

#to_hObject



37
38
39
# File 'lib/lux/response/lib/flash.rb', line 37

def to_h
  @msg
end