Class: Lux::Response::Flash
Class Method Summary collapse
-
.add_type(name) ⇒ Object
flash.info ‘messsage …’ flash.info = ‘messsage …’.
Instance Method Summary collapse
- #clear ⇒ Object
-
#clear_for_js ⇒ Object
clears white space, replaces quotes.
- #empty? ⇒ Boolean
-
#initialize(h = nil) ⇒ Flash
constructor
A new instance of Flash.
- #present? ⇒ Boolean
- #to_h ⇒ Object
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) { || add name, } eval "alias #{name}= #{name}" end |
Instance Method Details
#clear ⇒ Object
25 26 27 |
# File 'lib/lux/response/lib/flash.rb', line 25 def clear to_h.tap { @msg = {} } end |
#clear_for_js ⇒ Object
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 |
#present? ⇒ Boolean
29 30 31 |
# File 'lib/lux/response/lib/flash.rb', line 29 def present? @msg.keys.first end |
#to_h ⇒ Object
37 38 39 |
# File 'lib/lux/response/lib/flash.rb', line 37 def to_h @msg end |