Class: GoodData::CloudResources::CloudResourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/cloud_resources/cloud_resource_factory.rb

Class Method Summary collapse

Class Method Details

.create(type, data = {}, opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



14
15
16
17
18
19
# 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