class AlacrityRails::Transaction::Base
Public Class Methods
endpoint()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 23 def self.endpoint raise 'Must implement' end
net_http_start_arguments()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 18 def self.net_http_start_arguments @net_http_start_arguments ||= [endpoint.host, endpoint.port, use_ssl: endpoint.scheme == 'https'] end
new(data={})
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 3 def initialize(data={}) # May be overridden end
Public Instance Methods
absolute_time(datetime)
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 62 def absolute_time(datetime) datetime.strftime('%Q').to_i end
endpoint()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 26 def endpoint; self.class.endpoint end
finalize(response)
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 7 def finalize(response) # May be overridden end
net_http_start_arguments()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 21 def net_http_start_arguments; self.class.net_http_start_arguments end
post_request()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 11 def post_request Net::HTTP::Post.new(endpoint, { "Authorization" => authorization_header_value, "Content-Type" => "application/json" }).tap { |request| request.body = to_json } end
prepared_timeline_events()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 52 def prepared_timeline_events timeline_events.uniq do |timeline_event| timeline_event.values_at(:engine, :started_at, :finished_at, :detail).join('~') end.map do |timeline_event| timeline_event[:started_at] = absolute_time(timeline_event[:started_at].to_datetime) timeline_event[:finished_at] = absolute_time(timeline_event[:finished_at].to_datetime) timeline_event end end
store_metadata(data)
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 33 def store_metadata(data) # May be overridden end
store_timeline_event(data)
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 37 def store_timeline_event(data) timeline_events << { name: data[:name], event_type: data[:event_type], engine: data[:engine], started_at: data[:started_at], finished_at: data[:finished_at], detail: data[:detail] } end
timeline_events()
click to toggle source
# File lib/alacrity-rails/transaction/base.rb, line 48 def timeline_events @timeline_events ||= [] end