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



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

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

Instance Attribute Details

#options ⇒ Object (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#call(target) ⇒ Object



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

def call(target)
  form = template_klass.new(target, options).form
  return unless form.valid?

  @response = connection.post form.collection_path, body: form.attributes
  @response.to_h
end