Class: RocketJob::Batch::Statistics::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket_job/batch/statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Stats

hash [Hash]

Update an `in-memory` copy of the stats instead of gathering them inside `stats`.


14
15
16
17
# File 'lib/rocket_job/batch/statistics.rb', line 14

def initialize(hash = nil)
  @in_memory = hash
  @stats     = Hash.new(0) unless hash
end

Instance Attribute Details

#in_memoryObject (readonly)

Returns the value of attribute in_memory.



10
11
12
# File 'lib/rocket_job/batch/statistics.rb', line 10

def in_memory
  @in_memory
end

#statsObject (readonly)

Returns the value of attribute stats.



10
11
12
# File 'lib/rocket_job/batch/statistics.rb', line 10

def stats
  @stats
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rocket_job/batch/statistics.rb', line 35

def empty?
  stats.nil? || stats.empty?
end

#inc(hash) ⇒ Object



19
20
21
22
# File 'lib/rocket_job/batch/statistics.rb', line 19

def inc(hash)
  hash.each_pair { |key, increment| inc_key(key, increment) }
  self
end

#inc_key(key, increment = 1) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/rocket_job/batch/statistics.rb', line 24

def inc_key(key, increment = 1)
  return if increment == 0
  if in_memory
    # For tests and in-process execution
    inc_in_memory(key, increment)
  elsif key && key != ''
    stats["statistics.#{key}"] += increment
  end
  self
end