Sha256: 5b640f036a237c7074b222fb92a7e9de617e01e3d655bf288f09fcaf619c2ff6

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

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, options: {})
      if options[:fields]
        options[:fields].concat(self.known_fields).uniq
      else
        options[:fields] = self.known_fields
      end

      response = graph.get_connection(parent.id, api_path, options)
      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

2 entries across 2 versions & 1 rubygems

Version Path
eucalyptus-0.2.2 lib/eucalyptus/resource.rb
eucalyptus-0.2.1 lib/eucalyptus/resource.rb