Module: Theme::Events::Macros
- Defined in:
- lib/theme/events.rb
Instance Attribute Summary collapse
-
#_event_blocks ⇒ Object
Returns the value of attribute _event_blocks.
-
#_for_listeners ⇒ Object
Returns the value of attribute _for_listeners.
Instance Method Summary collapse
Instance Attribute Details
#_event_blocks ⇒ Object
Returns the value of attribute _event_blocks.
48 49 50 |
# File 'lib/theme/events.rb', line 48 def _event_blocks @_event_blocks end |
#_for_listeners ⇒ Object
Returns the value of attribute _for_listeners.
48 49 50 |
# File 'lib/theme/events.rb', line 48 def _for_listeners @_for_listeners end |
Instance Method Details
#on_event(name, options = {}, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/theme/events.rb', line 50 def on_event(name, = {}, &block) if id = [:for] (@_for_listeners ||= []) << id name = :"#{id}_#{name}" end @_event_blocks ||= {} @_event_blocks[name] = .fetch(:use) { block } mod = if const_defined?(:Events, false) const_get(:Events) else new_mod = Module.new do def self.to_s "Events(#{instance_methods(false).join(', ')})" end end const_set(:Events, new_mod) end include mod end |