Module: Cequel::Instrumentation::ModuleMethods
- Defined in:
- lib/cequel/instrumentation.rb
Overview
Metaprogramming method to wrap an existing method with instrumentation
Instance Method Summary collapse
-
#instrument(method_name, opts) ⇒ Object
Instruments ‘method_name` to publish the value returned by the `data_builder` proc onto `topic`.
Instance Method Details
#instrument(method_name, opts) ⇒ Object
Instruments ‘method_name` to publish the value returned by the `data_builder` proc onto `topic`
Example:
extend Instrumentation
instrument :create, data: {topic: "create.cequel", table_name: table_name}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cequel/instrumentation.rb', line 28 def instrument(method_name, opts) data = opts[:data] topic = opts.fetch(:topic, "#{method_name}.cequel") data_proc = if data.respond_to? :call data else ->(_) { data } end define_method(:"__data_for_#{method_name}_instrumentation", &data_proc) mod = Module.new mod.module_eval <<-METH def #{method_name}(*args) instrument("#{topic}", __data_for_#{method_name}_instrumentation(self)) do super(*args) end end METH prepend mod end |