Sha256: 9660f71d46debfa56f3aad9eb03403dd90cd4c119f2be7709a204f62bb474e03

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

require_relative '../mixins/packer'

module Trifle
  module Stats
    module Driver
      class Process
        include Mixins::Packer
        def initialize
          @data = {}
        end

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

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

        def get(key:)
          self.class.unpack(
            hash: @data.fetch(key, {})
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trifle-stats-0.2.1 lib/trifle/stats/driver/process.rb