Class: TokenOfFire::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/token_of_fire/scope.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_bus, filter = {}, single) ⇒ Scope

Returns a new instance of Scope.

Raises:

  • (RuntimeError)


3
4
5
6
7
8
# File 'lib/token_of_fire/scope.rb', line 3

def initialize(event_bus, filter={}, single)
  @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

#filterObject



42
43
44
# File 'lib/token_of_fire/scope.rb', line 42

def filter
  @filter
end

#subscriptionsObject



25
26
27
# File 'lib/token_of_fire/scope.rb', line 25

def subscriptions
  @subscriptions
end

#tokenObject

def dettach(:name_of_event) @scope_a.dettach(:name_of_event)



33
34
35
36
# File 'lib/token_of_fire/scope.rb', line 33

def token
  TokenOfFire::Token.new(@event_bus, self)
  #  starts with all subscriptions previously attached to a scope
end

#unique_tokenObject



38
39
40
# File 'lib/token_of_fire/scope.rb', line 38

def unique_token
  TokenOfFire::Token.new(@event_bus, self, true)
end