Class: ActionTracker::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/action_tracker/recorder.rb

Overview

Usage:

ActionTracker::Recorder.new(:create).call(order)

usage with wisper gem: (https://github.com/krisleech/wisper)

MyPublisher.suscribe(ActionTracker::Recorder.new(:update), on: :ok, with: :call)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_name, template_options = {}) ⇒ Recorder

Returns a new instance of Recorder.



17
18
19
20
# File 'lib/action_tracker/recorder.rb', line 17

def initialize(template_name, template_options = {})
  @template_name = template_name
  @options = template_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/action_tracker/recorder.rb', line 15

def options
  @options
end

Instance Method Details

#call(target) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
# File 'lib/action_tracker/recorder.rb', line 22

def call(target)
  form = options[:form] || build_form(target)
  return form.errors unless form.valid?
  raise EmptyTargetError, inspect unless target

  @response = ActionTracker::Workers::Factory.new(form).instance.perform
  @response.to_h
end