Class: Haken::Listeners
- Inherits:
-
Object
- Object
- Haken::Listeners
- Includes:
- Singleton
- Defined in:
- lib/haken/listeners.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Listeners
constructor
A new instance of Listeners.
- #load_hooks_for(view_context, identifier) ⇒ Object
- #subscribe(identifier, &block) ⇒ Object
Constructor Details
#initialize ⇒ Listeners
Returns a new instance of Listeners.
13 14 15 |
# File 'lib/haken/listeners.rb', line 13 def initialize @load_hooks = {} end |
Class Method Details
.load_hooks_for(identifier, *args) ⇒ Object
9 10 11 |
# File 'lib/haken/listeners.rb', line 9 def self.load_hooks_for(identifier, *args) instance.load_hooks_for(identifier, *args) end |
.subscribe(identifier, &block) ⇒ Object
5 6 7 |
# File 'lib/haken/listeners.rb', line 5 def self.subscribe(identifier, &block) instance.subscribe(identifier, &block) end |
Instance Method Details
#load_hooks_for(view_context, identifier) ⇒ Object
23 24 25 26 27 |
# File 'lib/haken/listeners.rb', line 23 def load_hooks_for(view_context, identifier) @load_hooks[identifier].map do |hook| view_context.instance_eval(&hook) end.join end |
#subscribe(identifier, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/haken/listeners.rb', line 17 def subscribe(identifier, &block) @load_hooks[identifier] ||= [] @load_hooks[identifier] << block end |