Class: Shouter::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/shouter/listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options) ⇒ Listener

Returns a new instance of Listener.



12
13
14
15
16
17
18
# File 'lib/shouter/listener.rb', line 12

def initialize(object, options)
  raise Shouter::ScopeMissingError unless options[:scope]

  @object = object
  @options = options
  @scope = options[:scope]
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



10
11
12
# File 'lib/shouter/listener.rb', line 10

def object
  @object
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/shouter/listener.rb', line 10

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/shouter/listener.rb', line 10

def scope
  @scope
end

Instance Method Details

#notify(scope, event, args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/shouter/listener.rb', line 20

def notify(scope, event, args, &block)
  return unless notification_allowed?(event, scope)

  if fire_guard!
    object.public_send(event, *args)
    fire_hook!(callback || block)

    Store.unregister(object) if single?
  end
end