class GoodData::Rest::ObjectFactory

Bridge between Rest::Object and Rest::Connection

MUST be Responsible for creating new Rest::Object instances using proper Rest::Connection SHOULD be used for throttling, statistics, custom ‘allocation strategies’ …

Attributes

client[RW]
connection[RW]
objects[RW]
resources[RW]

Public Class Methods

new(client) click to toggle source

Initializes instance of factory

@param connection [GoodData::Rest::Connection] Connection used by factory @return [GoodData::Rest::ObjectFactory] Factory instance

# File lib/gooddata/rest/object_factory.rb, line 25
def initialize(client)
  fail ArgumentError 'Invalid connection passed' if client.nil?

  @client = client

  # Set connection used by factory
  @connection = @client.connection
end

Public Instance Methods

create(type, data = {}, opts = {}) click to toggle source
# File lib/gooddata/rest/object_factory.rb, line 34
def create(type, data = {}, opts = {})
  res = type.new(data)
  res.client = client

  opts.each do |key, value|
    method = "#{key}="
    res.send(method, value) if res.respond_to?(method)
  end

  res
end
find(type, opts = {}) click to toggle source
# File lib/gooddata/rest/object_factory.rb, line 46
def find(type, opts = {})
  type.send('find', opts, @client)
end