class Csvsql::Tracker

Attributes

logger[R]
stats[R]

Public Class Methods

commit(*args, &block) click to toggle source
# File lib/csvsql/tracker.rb, line 16
def self.commit(*args, &block)
  tracker.commit(*args, &block)
end
new(logger = Logger.new('/dev/null')) click to toggle source
# File lib/csvsql/tracker.rb, line 20
def initialize(logger = Logger.new('/dev/null'))
  @stats = {}
  @logger = logger
end
tracker() click to toggle source
# File lib/csvsql/tracker.rb, line 8
def self.tracker
  @tracker ||= new
end
tracker=(t) click to toggle source
# File lib/csvsql/tracker.rb, line 12
def self.tracker=(t)
  @tracker = t
end

Public Instance Methods

commit(id, output: true, &block) click to toggle source
# File lib/csvsql/tracker.rb, line 25
def commit(id, output: true, &block)
  id = id.to_s
  old = stats[id]
  stats[id] = get_stat

  if block
    block.call.tap { commit(id) }
  elsif output && old
    logger.info("[#{id}] #{compare_stat(old, stats[id])}")
  end
end

Private Instance Methods

compare_stat(old, new) click to toggle source
# File lib/csvsql/tracker.rb, line 43
def compare_stat(old, new)
  "Time cost: #{((new[:time] - old[:time]) * 1000000).to_i / 1000}ms"
end
get_stat() click to toggle source
# File lib/csvsql/tracker.rb, line 39
def get_stat
  { time: Time.now }
end