Class: Trifle::Stats::Operations::Timeseries::Increment
- Inherits:
-
Object
- Object
- Trifle::Stats::Operations::Timeseries::Increment
- Defined in:
- lib/trifle/stats/operations/timeseries/increment.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(**keywords) ⇒ Increment
constructor
A new instance of Increment.
- #key_for(granularity:) ⇒ Object
- #perform ⇒ Object
- #tracking_key ⇒ Object
Constructor Details
#initialize(**keywords) ⇒ Increment
Returns a new instance of Increment.
10 11 12 13 14 15 16 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 10 def initialize(**keywords) @key = keywords.fetch(:key) @at = keywords.fetch(:at) @values = keywords.fetch(:values) @config = keywords[:config] @untracked = keywords.fetch(:untracked, false) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 8 def key @key end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 8 def values @values end |
Instance Method Details
#config ⇒ Object
18 19 20 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 18 def config @config || Trifle::Stats.default end |
#key_for(granularity:) ⇒ Object
22 23 24 25 26 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 22 def key_for(granularity:) pgrn = Nocturnal::Parser.new(granularity) at = Nocturnal.new(localized_time(@at), config: config).floor(pgrn.offset, pgrn.unit) Nocturnal::Key.new(key: key, granularity: granularity, at: at) end |
#perform ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 28 def perform payload = { keys: config.granularities.map { |granularity| key_for(granularity: granularity) }, values: values } if tracking_key config.storage.inc(**payload.merge(tracking_key: tracking_key)) else config.storage.inc(**payload) end end |
#tracking_key ⇒ Object
41 42 43 |
# File 'lib/trifle/stats/operations/timeseries/increment.rb', line 41 def tracking_key @untracked ? '__untracked__' : nil end |