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
# File 'lib/shouter/listener.rb', line 12

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

  @object = object
  @options = options
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

Instance Method Details

#for?(scope) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shouter/listener.rb', line 29

def for?(scope)
  options[:scope] == scope
end

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



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

def notify(event, args, &block)
  return unless object.respond_to?(event)
  if fire_guard!
    object.public_send(event, *args)
    fire_hook!(callback || block)

    Store.unregister(object) if single?
  end
end