Class: RocketJob::Batch::Statistics::Stats
- Inherits:
-
Object
- Object
- RocketJob::Batch::Statistics::Stats
- Defined in:
- lib/rocket_job/batch/statistics.rb
Instance Attribute Summary collapse
-
#in_memory ⇒ Object
readonly
Returns the value of attribute in_memory.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #inc(hash) ⇒ Object
- #inc_key(key, increment = 1) ⇒ Object
-
#initialize(hash = nil) ⇒ Stats
constructor
hash [Hash] Update an ‘in-memory` copy of the stats instead of gathering them inside `stats`.
Constructor Details
#initialize(hash = nil) ⇒ Stats
hash [Hash]
Update an `in-memory` copy of the stats instead of gathering them inside `stats`.
18 19 20 21 |
# File 'lib/rocket_job/batch/statistics.rb', line 18 def initialize(hash = nil) @in_memory = hash @stats = Hash.new(0) unless hash end |
Instance Attribute Details
#in_memory ⇒ Object (readonly)
Returns the value of attribute in_memory.
14 15 16 |
# File 'lib/rocket_job/batch/statistics.rb', line 14 def in_memory @in_memory end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
14 15 16 |
# File 'lib/rocket_job/batch/statistics.rb', line 14 def stats @stats end |
Instance Method Details
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/rocket_job/batch/statistics.rb', line 40 def empty? stats.nil? || stats.empty? end |
#inc(hash) ⇒ Object
23 24 25 26 |
# File 'lib/rocket_job/batch/statistics.rb', line 23 def inc(hash) hash.each_pair { |key, increment| inc_key(key, increment) } self end |
#inc_key(key, increment = 1) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rocket_job/batch/statistics.rb', line 28 def inc_key(key, increment = 1) return if increment.zero? if in_memory # For tests and in-process execution inc_in_memory(key, increment) elsif key && key != "" stats["statistics.#{key}"] += increment end self end |