Class: Csvsql::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/csvsql/tracker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = Logger.new('/dev/null')) ⇒ Tracker

Returns a new instance of Tracker.



20
21
22
23
# File 'lib/csvsql/tracker.rb', line 20

def initialize(logger = Logger.new('/dev/null'))
  @stats = {}
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/csvsql/tracker.rb', line 6

def logger
  @logger
end

#statsObject (readonly)

Returns the value of attribute stats.



6
7
8
# File 'lib/csvsql/tracker.rb', line 6

def stats
  @stats
end

Class Method Details

.commit(*args, &block) ⇒ Object



16
17
18
# File 'lib/csvsql/tracker.rb', line 16

def self.commit(*args, &block)
  tracker.commit(*args, &block)
end

.trackerObject



8
9
10
# File 'lib/csvsql/tracker.rb', line 8

def self.tracker
  @tracker ||= new
end

.tracker=(t) ⇒ Object



12
13
14
# File 'lib/csvsql/tracker.rb', line 12

def self.tracker=(t)
  @tracker = t
end

Instance Method Details

#commit(id, output: true, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# 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