Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/resugan/object.rb
Instance Method Summary collapse
- #_fire(event, params = {}) ⇒ Object
- #_listener(event, options = {}, &block) ⇒ Object
- #_listener!(event, options = {}, &block) ⇒ Object
- #resugan(namespace = '', &block) ⇒ Object
- #resugan!(namespace = '', &block) ⇒ Object
Instance Method Details
#_fire(event, params = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resugan/object.rb', line 26 def _fire(event, params = {}) params[:_source] = caller[0] if Resugan::Kernel.line_trace_enabled? current_thread = Thread.current if current_thread.resugan_context current_thread.resugan_context.register(event, params) else puts "WARN: #{event} called in #{caller[0]} but was not inside a resugan {} block" if Resugan::Kernel.warn_no_context_events? end end |
#_listener(event, options = {}, &block) ⇒ Object
37 38 39 40 41 |
# File 'lib/resugan/object.rb', line 37 def _listener(event, = {}, &block) Resugan::Kernel.register_with_namespace([:namespace], event, [:id], ->(params) { block.call(params) }) end |
#_listener!(event, options = {}, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/resugan/object.rb', line 43 def _listener!(event, = {}, &block) Resugan::Kernel.register_with_namespace([:namespace], event, [:id] || caller[0], ->(params) { block.call(params) }) end |
#resugan(namespace = '', &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/resugan/object.rb', line 2 def resugan(namespace = '', &block) namespace ||= '' current_thread = Thread.current current_thread.push_resugan_context(namespace) begin block.call ensure context = current_thread.pop_resugan_context end context end |
#resugan!(namespace = '', &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/resugan/object.rb', line 14 def resugan!(namespace = '', &block) namespace ||= '' current_thread = Thread.current current_thread.push_resugan_context(namespace, true) begin block.call ensure context = current_thread.pop_resugan_context(true) end context end |