Sha256: 8a4c80afacbfaa3b7063422a74c160ea92ba5a43879d66bbe45bb8c4b163b245

Contents?: true

Size: 856 Bytes

Versions: 9

Compression:

Stored size: 856 Bytes

Contents

module SnowmanIO
  class Metric
    include Mongoid::Document
    include Mongoid::Timestamps
    belongs_to :app
    has_many :checks, dependent: :destroy
    has_many :data_points, dependent: :destroy
    has_many :aggregations, dependent: :destroy

    KIND_AMOUNT = "amount"
    KIND_COUNTER = "counter"
    KIND_TIME = "time"

    field :name, type: String
    field :kind, type: String

    field :last_value, type: Float
    field :last_value_updated_at, type: DateTime

    def self.supported?(kind)
      kind.in? [
        KIND_AMOUNT,
        KIND_COUNTER,
        KIND_TIME
      ]
    end

    def as_json(options = {})
      super(options.merge(methods: [:check_ids])).tap do |o|
        o["id"]     = o.delete("_id").to_s
        o["app_id"] = o["app_id"].to_s
        o["check_ids"] = o["check_ids"].map(&:to_s)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/models/metric.rb
snowman-io-0.5.0 lib/snowman-io/models/metric.rb
snowman-io-0.4.0 lib/snowman-io/models/metric.rb
snowman-io-0.3.1 lib/snowman-io/models/metric.rb
snowman-io-0.3.0 lib/snowman-io/models/metric.rb
snowman-io-0.2.0 lib/snowman-io/models/metric.rb
snowman-io-0.1.0 lib/snowman-io/models/metric.rb
snowman-io-0.0.6 lib/snowman-io/models/metric.rb
snowman-io-0.0.5 lib/snowman-io/models/metric.rb