Module: BootyCall::Hook::ClassMethods
- Defined in:
- lib/booty_call/hook.rb
Instance Method Summary collapse
- #after(method_id, *args, &block) ⇒ Object
- #around(method_id, *args, &block) ⇒ Object
- #before(method_id, *args, &block) ⇒ Object
- #callback(position, method_id, *args, &block) ⇒ Object
- #observe(method_id, options = {}, &block) ⇒ Object
Instance Method Details
#after(method_id, *args, &block) ⇒ Object
21 22 23 |
# File 'lib/booty_call/hook.rb', line 21 def after(method_id, *args, &block) callback(:after, method_id, *args, &block) end |
#around(method_id, *args, &block) ⇒ Object
25 26 27 |
# File 'lib/booty_call/hook.rb', line 25 def around(method_id, *args, &block) callback(:around, method_id, *args, &block) end |
#before(method_id, *args, &block) ⇒ Object
17 18 19 |
# File 'lib/booty_call/hook.rb', line 17 def before(method_id, *args, &block) callback(:before, method_id, *args, &block) end |
#callback(position, method_id, *args, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/booty_call/hook.rb', line 34 def callback(position, method_id, *args, &block) case method_id when Regexp return if @introspector.observing?(method_id) observe(method_id, :times => :all) { |m| callback(position, m, *(args << block)) } @introspector.defined_methods \ .select { |m| m.to_s =~ method_id } \ .reject { |m| @introspector.observing?(m) } \ .each { |m| send(position, m, *args, &block) } when Symbol @introspector.has_method?(method_id) ? @callbacker.send(position, method_id, *args, &block) : observe(method_id) { send(position, method_id, *(args << block)) } end end |
#observe(method_id, options = {}, &block) ⇒ Object
29 30 31 32 |
# File 'lib/booty_call/hook.rb', line 29 def observe(method_id, ={}, &block) observer = [:meta] ? @meta_introspector : @introspector observer.observe(method_id, , &block) end |