Module: Cross::Talk::Listener::InstanceMethods

Defined in:
lib/cross-talk/listener.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*_) ⇒ Object



24
25
26
27
# File 'lib/cross-talk/listener.rb', line 24

def initialize(*_)
  register_hooks!
  super
end

#listen(klass, event, timing, &block) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/cross-talk/listener.rb', line 47

def listen(klass, event, timing, &block)
  event_name = "#{klass}##{event}:#{timing}"
  Cross::Talk.manager.notify('__new_hook:before', event_name)
  define_singleton_method event_name, &block
  Cross::Talk.manager.register(event_name, __get_receiver)
  Cross::Talk.manager.notify('__new_hook:after', event_name)
end

#register_hooks!Object



20
21
22
# File 'lib/cross-talk/listener.rb', line 20

def register_hooks!
  self.class.registration_hooks.each { |hook| hook.call(__get_receiver) }
end

#silence!Object



33
34
35
# File 'lib/cross-talk/listener.rb', line 33

def silence!
  @__silenced = true
end

#silenced?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/cross-talk/listener.rb', line 29

def silenced?
  @__silenced
end

#silently(&block) ⇒ Object



41
42
43
44
45
# File 'lib/cross-talk/listener.rb', line 41

def silently(&block)
  silence!
  block.call
  unsilence!
end

#unsilence!Object



37
38
39
# File 'lib/cross-talk/listener.rb', line 37

def unsilence!
  @__silenced = false
end