Sha256: a29bff4dba2ec5cc24043cb39dced355d96cd28355e966ecffcf09379a351c6e

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2019 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 'active_support/core_ext/string/inflections'
require_relative 'cloud_resource_client'

module GoodData
  module CloudResources
    class CloudResourceFactory
      class << self
        def load_cloud_resource(type)
          base = "#{Pathname(__FILE__).dirname.expand_path}#{File::SEPARATOR}#{type}#{File::SEPARATOR}"
          Dir.glob(base + '**/*.rb').each do |file|
            require file
          end
        end

        def create(type, data = {}, opts = {})
          load_cloud_resource(type)
          clients = CloudResourceClient.descendants.select { |c| c.respond_to?("accept?") && c.send("accept?", type) }
          raise "DataSource does not support type \"#{type}\"" if clients.empty?

          res = clients[0].new(data)
          opts.each do |key, value|
            method = "#{key}="
            res.send(method, value) if res.respond_to?(method)
          end
          res
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gooddata-2.3.1-java lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.3.1 lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.3.0-java lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.3.0 lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.2.0-java lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.2.0 lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.1.19-java lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.1.19 lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.1.17-java lib/gooddata/cloud_resources/cloud_resource_factory.rb
gooddata-2.1.17 lib/gooddata/cloud_resources/cloud_resource_factory.rb