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.



18
19
20
21
# File 'lib/csvsql/tracker.rb', line 18

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

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/csvsql/tracker.rb', line 4

def logger
  @logger
end

#statsObject (readonly)

Returns the value of attribute stats.



4
5
6
# File 'lib/csvsql/tracker.rb', line 4

def stats
  @stats
end

Class Method Details

.commit(*args, &block) ⇒ Object



14
15
16
# File 'lib/csvsql/tracker.rb', line 14

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

.trackerObject



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

def self.tracker
  @tracker ||= new
end

.tracker=(t) ⇒ Object



10
11
12
# File 'lib/csvsql/tracker.rb', line 10

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

Instance Method Details

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/csvsql/tracker.rb', line 23

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