Sha256: 0dc3eeedd9947a4489f3e54a43f17090ade4fc5b1d56374c1417521de2ddf8fb

Contents?: true

Size: 985 Bytes

Versions: 1

Compression:

Stored size: 985 Bytes

Contents

module Eucalyptus
  class Resource
    def self.api_path
      raise "You must implement #{__method__.to_s}"
    end

    def self.known_fields
      raise "You must implement #{__method__.to_s}"
    end

    def self.parent
      Account.all.last
    end

    def self.find(id, fields: [], graph: Eucalyptus.graph)
      fields.concat(self.known_fields).uniq

      response = graph.get_object(id, fields: fields)
      self.new(response)
    end

    def self.all(graph: Eucalyptus.graph, parent: self.parent, fields: [])
      fields.concat(self.known_fields).uniq

      response = graph.get_connection(parent.id, api_path, fields: fields)
      response.collect{ |res| self.new(res) }
    end

    def initialize(response)
      @response = Response.new(response)
    end

    def method_missing(method_sym, *args, &block)
      @response.send(method_sym)
    end

    def respond_to?(method_sym, include_private = false)
      @response.respond_to?(method_sym)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eucalyptus-0.2.0 lib/eucalyptus/resource.rb