Module: InstrumentAllTheThings::MethodProxy
- Defined in:
- lib/instrument_all_the_things/method_proxy.rb
Defined Under Namespace
Modules: Instrumentor
Class Method Summary collapse
- .construct_for_class(klass) ⇒ Object
- .find_for_class(klass) ⇒ Object
- .for_class(klass) ⇒ Object
- .install_on_class(klass) ⇒ Object
Class Method Details
.construct_for_class(klass) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/instrument_all_the_things/method_proxy.rb', line 26 def self.construct_for_class(klass) mod = Module.new do extend Instrumentor end # attaching to the original to_s method = klass.method(:to_s) mod.define_singleton_method(:to_s, &method) mod._iatt_built_for = klass mod end |
.find_for_class(klass) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/instrument_all_the_things/method_proxy.rb', line 13 def self.find_for_class(klass) klass.ancestors.detect do |a| a.is_a?(Instrumentor) && a._iatt_built_for == klass end end |
.for_class(klass) ⇒ Object
9 10 11 |
# File 'lib/instrument_all_the_things/method_proxy.rb', line 9 def self.for_class(klass) find_for_class(klass) || install_on_class(klass) end |
.install_on_class(klass) ⇒ Object
20 21 22 23 24 |
# File 'lib/instrument_all_the_things/method_proxy.rb', line 20 def self.install_on_class(klass) construct_for_class(klass).tap do |m| klass.prepend(m) end end |