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`.
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_memory ⇒ Object (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 |
#stats ⇒ Object (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
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 |