Module: BusinessFlow::Instrument::ClassMethods
- Defined in:
- lib/business_flow/instrument.rb
Overview
Contains methods that we add to the DSL
Constant Summary collapse
- INSTRUMENTATION_PREFIX =
'business_flow'
Class Method Summary collapse
Instance Method Summary collapse
- #event_name ⇒ Object
- #instrument(name, flow) ⇒ Object
- #instrument_steps ⇒ Object
- #instrumentation_name ⇒ Object
- #with_instrument_payload(payload = nil, opts = {}, &blk) ⇒ Object
Class Method Details
.instrument_payload(flow) ⇒ Object
26 27 28 |
# File 'lib/business_flow/instrument.rb', line 26 def self.instrument_payload(flow) catch(:halt_step) { flow.class.with_instrument_payload.call(flow)&.merge_into(flow) } end |
Instance Method Details
#event_name ⇒ Object
48 49 50 51 |
# File 'lib/business_flow/instrument.rb', line 48 def event_name @event_name ||= "#{INSTRUMENTATION_PREFIX}.flow.#{instrumentation_name}" end |
#instrument(name, flow) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/business_flow/instrument.rb', line 30 def instrument(name, flow) payload = { flow: flow }.merge(ClassMethods.instrument_payload(flow)) ActiveSupport::Notifications.instrument( "#{INSTRUMENTATION_PREFIX}.#{name}.#{instrumentation_name}", payload ) do yield payload end end |
#instrument_steps ⇒ Object
39 40 41 |
# File 'lib/business_flow/instrument.rb', line 39 def instrument_steps step_executor ::BusinessFlow::InstrumentedStepExecutor end |
#instrumentation_name ⇒ Object
43 44 45 46 |
# File 'lib/business_flow/instrument.rb', line 43 def instrumentation_name @instrumentation_name ||= to_s.underscore.freeze end |
#with_instrument_payload(payload = nil, opts = {}, &blk) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/business_flow/instrument.rb', line 16 def with_instrument_payload(payload = nil, opts = {}, &blk) if payload.is_a?(Hash) @payload = Step.new(Callable.new(proc { payload }), {}) elsif payload || blk @payload = Step.new(Callable.new(payload || blk), { default_output: :instrument_payload}.merge(opts)) else @payload ||= Step.new(Callable.new(proc { {} }), opts) end end |