Class: Trifle::Stats::Driver::Process

Inherits:
Object
  • Object
show all
Includes:
Mixins::Packer
Defined in:
lib/trifle/stats/driver/process.rb

Instance Method Summary collapse

Methods included from Mixins::Packer

included

Constructor Details

#initializeProcess

Returns a new instance of Process.



10
11
12
13
# File 'lib/trifle/stats/driver/process.rb', line 10

def initialize
  @data = {}
  @separator = '::'
end

Instance Method Details

#get(keys:) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/trifle/stats/driver/process.rb', line 35

def get(keys:)
  keys.map do |key|
    self.class.unpack(
      hash: @data.fetch(key.join(@separator), {})
    )
  end
end

#inc(keys:, **values) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/trifle/stats/driver/process.rb', line 15

def inc(keys:, **values)
  keys.map do |key|
    self.class.pack(hash: values).each do |k, c|
      d = @data.fetch(key.join(@separator), {})
      d[k] = d[k].to_i + c
      @data[key.join(@separator)] = d
    end
  end
end

#set(keys:, **values) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/trifle/stats/driver/process.rb', line 25

def set(keys:, **values)
  keys.map do |key|
    self.class.pack(hash: values).each do |k, c|
      d = @data.fetch(key.join(@separator), {})
      d[k] = c
      @data[key.join(@separator)] = d
    end
  end
end