class GoodData::CloudResources::CloudResourceFactory

Public Class Methods

create(type, data = {}, opts = {}) click to toggle source
# File lib/gooddata/cloud_resources/cloud_resource_factory.rb, line 21
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
load_cloud_resource(type) click to toggle source
# File lib/gooddata/cloud_resources/cloud_resource_factory.rb, line 14
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