Class: Minds::Datasources
- Inherits:
-
Object
- Object
- Minds::Datasources
- Defined in:
- lib/minds/datasources.rb
Instance Method Summary collapse
-
#all ⇒ Array<Datasource>
Return a list of datasources.
-
#create(ds_config, update = false) ⇒ Datasource
Create a new datasource and return it.
-
#destroy(name, force: false) ⇒ Object
Delete a datasource.
-
#find(name) ⇒ Datasource
Find a datasource by name.
-
#initialize(client:) ⇒ Datasources
constructor
A new instance of Datasources.
Constructor Details
#initialize(client:) ⇒ Datasources
Returns a new instance of Datasources.
28 29 30 |
# File 'lib/minds/datasources.rb', line 28 def initialize(client:) @client = client end |
Instance Method Details
#all ⇒ Array<Datasource>
Return a list of datasources
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/minds/datasources.rb', line 77 def all data = @client.get(path: "datasources") return [] if data.empty? data.each_with_object([]) do |item, ds_list| next if item["engine"].nil? ds_list << Datasource.new(**item.transform_keys(&:to_sym)) end end |
#create(ds_config, update = false) ⇒ Datasource
Create a new datasource and return it
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/minds/datasources.rb', line 57 def create(ds_config, update = false) name = ds_config.name Validators.validate_datasource_name!(name) path = "datasources" path += "/#{name}" if update @client.send(update ? :put : :post, path: path, parameters: ds_config.to_h) find(name) end |
#destroy(name, force: false) ⇒ Object
Delete a datasource
118 119 120 121 |
# File 'lib/minds/datasources.rb', line 118 def destroy(name, force: false) data = force ? { cascade: true } : nil @client.delete(path: "datasources/#{name}", parameters: data) end |
#find(name) ⇒ Datasource
Find a datasource by name
98 99 100 101 102 103 104 |
# File 'lib/minds/datasources.rb', line 98 def find(name) data = @client.get(path: "datasources/#{name}") if data["engine"].nil? raise ObjectNotSupported, "Wrong type of datasource: #{name}" end Datasource.new(**data.transform_keys(&:to_sym)) end |