Class: Runaround::Manager
- Inherits:
-
Object
- Object
- Runaround::Manager
- Defined in:
- lib/runaround/manager.rb
Instance Attribute Summary collapse
-
#apply ⇒ Object
readonly
Returns the value of attribute apply.
-
#for_instances ⇒ Object
readonly
Returns the value of attribute for_instances.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
- #after(method, fifo: true, &block) ⇒ Object
- #around(method, fifo: false, &block) ⇒ Object
- #before(method, fifo: true, &block) ⇒ Object
- #callbacks(method) ⇒ Object
- #import(other) ⇒ Object
-
#initialize(receiver, apply: true, for_instances: false) ⇒ Manager
constructor
A new instance of Manager.
- #to_h ⇒ Object
Constructor Details
#initialize(receiver, apply: true, for_instances: false) ⇒ Manager
Returns a new instance of Manager.
9 10 11 12 13 |
# File 'lib/runaround/manager.rb', line 9 def initialize(receiver, apply: true, for_instances: false) @receiver = receiver @apply = !!apply @for_instances = !!for_instances end |
Instance Attribute Details
#apply ⇒ Object (readonly)
Returns the value of attribute apply.
7 8 9 |
# File 'lib/runaround/manager.rb', line 7 def apply @apply end |
#for_instances ⇒ Object (readonly)
Returns the value of attribute for_instances.
7 8 9 |
# File 'lib/runaround/manager.rb', line 7 def for_instances @for_instances end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
7 8 9 |
# File 'lib/runaround/manager.rb', line 7 def receiver @receiver end |
Instance Method Details
#after(method, fifo: true, &block) ⇒ Object
20 21 22 23 |
# File 'lib/runaround/manager.rb', line 20 def after(method, fifo: true, &block) prepare_callback( method: method, type: :after, fifo: fifo, &block) end |
#around(method, fifo: false, &block) ⇒ Object
25 26 27 28 |
# File 'lib/runaround/manager.rb', line 25 def around(method, fifo: false, &block) prepare_callback( method: method, type: :around, fifo: fifo, &block) end |
#before(method, fifo: true, &block) ⇒ Object
15 16 17 18 |
# File 'lib/runaround/manager.rb', line 15 def before(method, fifo: true, &block) prepare_callback( method: method, type: :before, fifo: fifo, &block) end |
#callbacks(method) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/runaround/manager.rb', line 30 def callbacks(method) all = all_callbacks(method) blocks = all.dup.tap{ |h| h.delete(:around) } fibers = all[:around].map{ |b| Fiber.new(&b) } return blocks, fibers end |
#import(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/runaround/manager.rb', line 43 def import(other) validate_manager!(other) other.to_h.each do |method, callbacks| callbacks.each do |type, list| list.each do |block| prepare_callback( method: method, type: type, fifo: true, &block) end end end end |
#to_h ⇒ Object
37 38 39 40 41 |
# File 'lib/runaround/manager.rb', line 37 def to_h callback_hooks.keys.reduce({}) do |h, method| h[method] = copy_callback_map(method); h end end |