Module: Clockblock::Timing::ClassMethods
- Defined in:
- lib/clockblock/timing.rb
Instance Method Summary collapse
- #add_timing_to(*methods) ⇒ Object
- #add_timing_to_method(method) ⇒ Object
- #future_method_added(method) ⇒ Object
- #method_added(method) ⇒ Object
- #receiver ⇒ Object
- #singleton_method_added(method) ⇒ Object
- #stashed_method_name_for(method) ⇒ Object
Instance Method Details
#add_timing_to(*methods) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/clockblock/timing.rb', line 30 def add_timing_to *methods methods.each do |method| if receiver.method_defined?(method) && !receiver.method_defined?(stashed_method_name_for(method)) add_timing_to_method method else @future_timer_methods ||= Set.new @future_timer_methods << method end end end |
#add_timing_to_method(method) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/clockblock/timing.rb', line 15 def add_timing_to_method(method) stashed_method = stashed_method_name_for method receiver.class_eval do alias_method stashed_method, method define_method method do |*args, &block| @clockblock_timers ||= {} @clockblock_timers[method] = Clockblock::Timer.new @clockblock_timers[method].clock(method) do send stashed_method, *args, &block end end end end |
#future_method_added(method) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/clockblock/timing.rb', line 41 def future_method_added(method) if !@added_by_clockblock && @future_timer_methods && @future_timer_methods.include?(method) @added_by_clockblock = true @future_timer_methods.subtract [method] add_timing_to_method method @added_by_clockblock = false end end |
#method_added(method) ⇒ Object
50 51 52 |
# File 'lib/clockblock/timing.rb', line 50 def method_added(method) future_method_added method end |
#receiver ⇒ Object
7 8 9 |
# File 'lib/clockblock/timing.rb', line 7 def receiver self.is_a?(Class) ? self : self.singleton_class end |
#singleton_method_added(method) ⇒ Object
54 55 56 |
# File 'lib/clockblock/timing.rb', line 54 def singleton_method_added(method) future_method_added method end |
#stashed_method_name_for(method) ⇒ Object
11 12 13 |
# File 'lib/clockblock/timing.rb', line 11 def stashed_method_name_for(method) "#{method}_stashed_by_clockblock".to_sym end |