Class: TokenOfFire::Scope
- Inherits:
-
Object
- Object
- TokenOfFire::Scope
- Defined in:
- lib/token_of_fire/scope.rb
Instance Method Summary collapse
- #attach(event_name, handler, method_name) ⇒ Object
- #attach_subscriptions(list) ⇒ Object
- #filter ⇒ Object
-
#initialize(event_bus, filter = {}) ⇒ Scope
constructor
A new instance of Scope.
- #scope(filter = {}) ⇒ Object
- #subscriptions ⇒ Object
-
#token ⇒ Object
def dettach(:name_of_event) @scope_a.dettach(:name_of_event).
- #unique_token ⇒ Object
Constructor Details
#initialize(event_bus, filter = {}) ⇒ Scope
Returns a new instance of Scope.
3 4 5 6 7 8 |
# File 'lib/token_of_fire/scope.rb', line 3 def initialize(event_bus, filter={}) @event_bus = event_bus raise RuntimeError, "Provide hash please" unless filter.is_a? Hash @filter = filter @subscriptions = [] end |
Instance Method Details
#attach(event_name, handler, method_name) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/token_of_fire/scope.rb', line 16 def attach(event_name, handler, method_name) @subscriptions.push({ :event_name => event_name, :handler => handler, :method_name => method_name }) @subscriptions end |
#attach_subscriptions(list) ⇒ Object
10 11 12 13 14 |
# File 'lib/token_of_fire/scope.rb', line 10 def attach_subscriptions(list) list.each do |t| attach(t[0], t[1], t[2]) end end |
#filter ⇒ Object
46 47 48 |
# File 'lib/token_of_fire/scope.rb', line 46 def filter @filter end |
#scope(filter = {}) ⇒ Object
25 26 27 |
# File 'lib/token_of_fire/scope.rb', line 25 def scope(filter={}) TokenOfFire::Scope.new(@event_bus, @filter.merge(filter)) end |
#subscriptions ⇒ Object
29 30 31 |
# File 'lib/token_of_fire/scope.rb', line 29 def subscriptions @subscriptions end |
#token ⇒ Object
def dettach(:name_of_event) @scope_a.dettach(:name_of_event)
37 38 39 40 |
# File 'lib/token_of_fire/scope.rb', line 37 def token TokenOfFire::Token.new(@event_bus, self) # starts with all subscriptions previously attached to a scope end |
#unique_token ⇒ Object
42 43 44 |
# File 'lib/token_of_fire/scope.rb', line 42 def unique_token TokenOfFire::Token.new(@event_bus, self, true) end |