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