Class: GoodData::Rest::ObjectFactory
- 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
-
#client ⇒ Object
Returns the value of attribute client.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#resources ⇒ Object
Returns the value of attribute resources.
Class Method Summary collapse
-
.objects ⇒ Array<GoodData::Rest::Object>
Gets list of all GoodData::Rest::Object subclasses.
-
.resources ⇒ Array<GoodData::Rest::Resource>
Gets list of all GoodData::Rest::Resource subclasses.
Instance Method Summary collapse
- #create(type, data = {}, opts = {}) ⇒ Object
- #find(type, opts = {}) ⇒ Object
-
#initialize(client) ⇒ GoodData::Rest::ObjectFactory
constructor
Initializes instance of factory.
Constructor Details
#initialize(client) ⇒ GoodData::Rest::ObjectFactory
Initializes instance of factory
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
#client ⇒ Object
Returns the value of attribute client.
16 17 18 |
# File 'lib/gooddata/rest/object_factory.rb', line 16 def client @client end |
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/gooddata/rest/object_factory.rb', line 17 def connection @connection end |
#objects ⇒ Object
Returns the value of attribute objects.
18 19 20 |
# File 'lib/gooddata/rest/object_factory.rb', line 18 def objects @objects end |
#resources ⇒ Object
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
.objects ⇒ Array<GoodData::Rest::Object>
Gets list of all GoodData::Rest::Object subclasses
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 |
.resources ⇒ Array<GoodData::Rest::Resource>
Gets list of all GoodData::Rest::Resource subclasses
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 |