Class: ForestAdminDatasourceToolkit::Datasource
- Inherits:
-
Components::Contracts::DatasourceContract
- Object
- Components::Contracts::DatasourceContract
- ForestAdminDatasourceToolkit::Datasource
- Defined in:
- lib/forest_admin_datasource_toolkit/datasource.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#live_query_connections ⇒ Object
readonly
Returns the value of attribute live_query_connections.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #add_chart(chart) ⇒ Object
- #add_collection(collection) ⇒ Object
- #build_binding_symbol(_connection_name, _binds) ⇒ Object
- #execute_native_query(_connection_name, _query, _binds) ⇒ Object
- #get_collection(name) ⇒ Object
-
#initialize ⇒ Datasource
constructor
A new instance of Datasource.
- #render_chart(_caller, name) ⇒ Object
Constructor Details
#initialize ⇒ Datasource
Returns a new instance of Datasource.
5 6 7 8 9 10 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 5 def initialize super @schema = { charts: [] } @collections = {} @live_query_connections = {} end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
3 4 5 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 3 def collections @collections end |
#live_query_connections ⇒ Object (readonly)
Returns the value of attribute live_query_connections.
3 4 5 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 3 def live_query_connections @live_query_connections end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
3 4 5 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 3 def schema @schema end |
Instance Method Details
#add_chart(chart) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 38 def add_chart(chart) if @schema[:charts].any? do |c| c[:name] == chart[:name] end raise Exceptions::ForestException, "Chart #{chart[:name]} already defined in datasource" end @schema[:charts] << chart end |
#add_collection(collection) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 18 def add_collection(collection) if @collections.key? collection.name raise Exceptions::ForestException, "Collection #{collection.name} already defined in datasource" end @collections[collection.name] = collection end |
#build_binding_symbol(_connection_name, _binds) ⇒ Object
34 35 36 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 34 def build_binding_symbol(_connection_name, _binds) raise Exceptions::ForestException, 'this datasource do not support native query.' end |
#execute_native_query(_connection_name, _query, _binds) ⇒ Object
30 31 32 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 30 def execute_native_query(_connection_name, _query, _binds) raise Exceptions::ForestException, 'this datasource do not support native query.' end |
#get_collection(name) ⇒ Object
12 13 14 15 16 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 12 def get_collection(name) raise Exceptions::ForestException, "Collection #{name} not found." unless @collections.key? name @collections[name] end |
#render_chart(_caller, name) ⇒ Object
26 27 28 |
# File 'lib/forest_admin_datasource_toolkit/datasource.rb', line 26 def render_chart(_caller, name) raise Exceptions::ForestException, "No chart named #{name} exists on this datasource." end |