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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes instance of factory

Parameters:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gooddata/rest/object_factory.rb', line 44

def initialize(client)
  fail ArgumentError 'Invalid connection passed' if client.nil?

  @client = client

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

  # Initialize internal factory map of GoodData::Rest::Object instances
  @objects = ObjectFactory.objects

  # Initialize internal factory map of GoodData::Rest::Resource instances
  @resources = ObjectFactory.resources
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

Class Method Details

.objectsArray<GoodData::Rest::Object>

Gets list of all GoodData::Rest::Object subclasses

Returns:



28
29
30
# File 'lib/gooddata/rest/object_factory.rb', line 28

def objects
  ObjectSpace.each_object(Class).select { |klass| klass < GoodData::Rest::Object }
end

.resourcesArray<GoodData::Rest::Resource>

Gets list of all GoodData::Rest::Resource subclasses

Returns:



35
36
37
# File 'lib/gooddata/rest/object_factory.rb', line 35

def resources
  ObjectSpace.each_object(Class).select { |klass| klass < GoodData::Rest::Resource }
end

Instance Method Details

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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gooddata/rest/object_factory.rb', line 59

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



71
72
73
# File 'lib/gooddata/rest/object_factory.rb', line 71

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