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.
73 74 75 |
# File 'lib/theme/events.rb', line 73 def _event_blocks @_event_blocks end |
#_for_listeners ⇒ Object
Returns the value of attribute _for_listeners.
73 74 75 |
# File 'lib/theme/events.rb', line 73 def _for_listeners @_for_listeners end |
Instance Method Details
#on_event(name, options = {}, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/theme/events.rb', line 75 def on_event(name, = {}, &block) if id = [:for] (@_for_listeners ||= []) << id name = :"for_#{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 |