Sha256: 7c26f708e78dcb807e3e22f0fa61a8e26f36d01b0e374801ae4fa17d1f429157

Contents?: true

Size: 1.41 KB

Versions: 73

Compression:

Stored size: 1.41 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require_relative 'object'

module GoodData
  module Rest
    # 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' ...
    class ObjectFactory
      attr_accessor :client
      attr_accessor :connection
      attr_accessor :objects
      attr_accessor :resources

      # Initializes instance of factory
      #
      # @param connection [GoodData::Rest::Connection] Connection used by factory
      # @return [GoodData::Rest::ObjectFactory] Factory instance
      def initialize(client)
        fail ArgumentError 'Invalid connection passed' if client.nil?

        @client = client

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

      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

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

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
gooddata-2.3.1-java lib/gooddata/rest/object_factory.rb
gooddata-2.3.1 lib/gooddata/rest/object_factory.rb
gooddata-2.3.0-java lib/gooddata/rest/object_factory.rb
gooddata-2.3.0 lib/gooddata/rest/object_factory.rb
gooddata-2.2.0-java lib/gooddata/rest/object_factory.rb
gooddata-2.2.0 lib/gooddata/rest/object_factory.rb
gooddata-2.1.19-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.19 lib/gooddata/rest/object_factory.rb
gooddata-2.1.17-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.17 lib/gooddata/rest/object_factory.rb
gooddata-2.1.15-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.15 lib/gooddata/rest/object_factory.rb
gooddata-2.1.14-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.14 lib/gooddata/rest/object_factory.rb
gooddata-2.1.13-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.13 lib/gooddata/rest/object_factory.rb
gooddata-2.1.12-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.12 lib/gooddata/rest/object_factory.rb
gooddata-2.1.11-java lib/gooddata/rest/object_factory.rb
gooddata-2.1.11 lib/gooddata/rest/object_factory.rb