Sha256: 52acea718ad10cf8e1244a05ea99c049e6423b5521d528198ee69d07b188cad9
Contents?: true
Size: 752 Bytes
Versions: 4
Compression:
Stored size: 752 Bytes
Contents
require 'logger' class Csvsql::Tracker attr_reader :stats, :logger def self.tracker @tracker ||= new end def self.tracker=(t) @tracker = t end def self.commit(*args, &block) tracker.commit(*args, &block) end def initialize(logger = Logger.new('/dev/null')) @stats = {} @logger = logger end 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 def get_stat { time: Time.now } end def compare_stat(old, new) "Time cost: #{((new[:time] - old[:time]) * 1000000).to_i / 1000}ms" end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
csvsql-0.1.4 | lib/csvsql/tracker.rb |
csvsql-0.1.3 | lib/csvsql/tracker.rb |
csvsql-0.1.2 | lib/csvsql/tracker.rb |
csvsql-0.1.1 | lib/csvsql/tracker.rb |