Sha256: b4f914d61cd543d2421bbfadd443c0ebb2a0c7644bddd4c2c87a01d8e4e2a13d

Contents?: true

Size: 1.04 KB

Versions: 33

Compression:

Stored size: 1.04 KB

Contents

require 'time'
module Yao::Resources
  class Resource < Base
    friendly_attributes :user_id, :resource_id, :project_id,
                        :last_sample_timestamp, :first_sample_timestamp,
                        :metadata,
                        :links

    def id
      resource_id
    end

    def tenant
      @tenant ||= Yao::User.get(project_id)
    end

    def user
      @user ||= Yao::User.get(user_id)
    end

    def last_sampled_at
      Time.parse last_sample_timestamp
    end

    def first_sampled_at
      Time.parse first_sample_timestamp
    end

    def get_meter(name)
      if link = links.find{|l| l["rel"] == name }
        Yao::Sample.list(link["href"])
      end
    end

    def meters
      links.map{|l| l["rel"] }.delete_if{|n| n == 'self' }
    end

    self.service        = "metering"
    self.api_version    = "v2"
    self.resources_name = "resources"

    class << self
      private
      def resource_from_json(json)
        json
      end

      def resources_from_json(json)
        json
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
yao-0.2.12 lib/yao/resources/resource.rb
yao-0.2.11 lib/yao/resources/resource.rb
yao-0.2.10 lib/yao/resources/resource.rb
yao-0.2.9 lib/yao/resources/resource.rb
yao-0.2.8 lib/yao/resources/resource.rb
yao-0.2.7 lib/yao/resources/resource.rb
yao-0.2.6 lib/yao/resources/resource.rb
yao-0.2.5 lib/yao/resources/resource.rb
yao-0.2.4 lib/yao/resources/resource.rb
yao-0.2.2 lib/yao/resources/resource.rb
yao-0.2.1 lib/yao/resources/resource.rb
yao-0.2.0 lib/yao/resources/resource.rb
yao-0.2.0.rc1 lib/yao/resources/resource.rb