Class: GoodData::Rest::ObjectFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/rest/object_factory.rb

Overview

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' ...

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ GoodData::Rest::ObjectFactory

Initializes instance of factory

Parameters:



25
26
27
28
29
30
31
32
# 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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



16
17
18
# File 'lib/gooddata/rest/object_factory.rb', line 16

def client
  @client
end

#connectionObject

Returns the value of attribute connection.



17
18
19
# File 'lib/gooddata/rest/object_factory.rb', line 17

def connection
  @connection
end

#objectsObject

Returns the value of attribute objects.



18
19
20
# File 'lib/gooddata/rest/object_factory.rb', line 18

def objects
  @objects
end

#resourcesObject

Returns the value of attribute resources.



19
20
21
# File 'lib/gooddata/rest/object_factory.rb', line 19

def resources
  @resources
end

Instance Method Details

#create(type, data = {}, opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# 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 = {}) ⇒ Object



46
47
48
# File 'lib/gooddata/rest/object_factory.rb', line 46

def find(type, opts = {})
  type.send('find', opts, @client)
end