class Splash::Transfers::TxRecords

Public Class Methods

new(name) click to toggle source
# File lib/splash/transfers.rb, line 54
def initialize(name)
  @name = name
  @backend = get_backend :transfers_trace
end

Public Instance Methods

add_record(record) click to toggle source
# File lib/splash/transfers.rb, line 76
def add_record(record)
  data = get_all_records
  data.push({ DateTime.now.to_s => record })
  @backend.put key: @name, value: data.to_yaml
end
check_prepared() click to toggle source
# File lib/splash/transfers.rb, line 86
def check_prepared
  return :never_run_prepare unless @backend.exist?({key: @name})
  return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item|
    record =item.keys.first
    value=item[record]
    value[:status] == :prepared
  }.count > 0
  return :prepared
end
get_all_records(options={}) click to toggle source
# File lib/splash/transfers.rb, line 82
def get_all_records(options={})
  return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
end
purge(retention) click to toggle source
# File lib/splash/transfers.rb, line 59
def purge(retention)
  retention = {} if retention.nil?
  if retention.include? :hours then
    adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
  elsif retention.include? :hours then
    adjusted_datetime = DateTime.now - retention[:days].to_i
  else
    adjusted_datetime = DateTime.now - DEFAULT_RETENTION
  end

  data = get_all_records

  data.delete_if { |item|
    DateTime.parse(item.keys.first) <= (adjusted_datetime)}
  @backend.put key: @name, value: data.to_yaml
end