Sha256: 973e4868f4ea42392deddcac40d3e90417f7fb5e8139463f4dd185600145d983

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

module Chillout
  class CreationsContainer
    def initialize
      @container = Hash.new {|hash, key| hash[key] = 0}
    end

    def increment!(class_name, value=1)
      key = key(class_name)
      @container[key] += value
    end

    def [](name)
      key = key(name)
      @container[key]
    end

    def key(name)
      name.to_sym
    end

    def each(&proc)
      @container.each(&proc)
    end

    def resource_keys
      @container.keys
    end

    def merge(other_container)
      for key in other_container.resource_keys
        increment!(key, other_container[key])
      end
    end

    def ==(other)
      self.class == other.class &&
      @container == other.instance_variable_get(:@container)
    end

    def empty?
      @container.empty?
    end

    def as_measurements(timestamp = Time.now)
      iso_timestamp = timestamp.iso8601
      @container.each.map do |model_name, value|
        {
          series: model_name.to_s,
          tags: {},
          timestamp: iso_timestamp,
          values: { creations: value },
        }
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
chillout-0.8.9 lib/chillout/creations_container.rb
chillout-0.8.5.1 lib/chillout/creations_container.rb
chillout-0.8.8 lib/chillout/creations_container.rb
chillout-0.8.7 lib/chillout/creations_container.rb
chillout-0.8.6 lib/chillout/creations_container.rb
chillout-0.8.5 lib/chillout/creations_container.rb
chillout-0.8.4 lib/chillout/creations_container.rb
chillout-0.8.3 lib/chillout/creations_container.rb