Class: ForestAdminDatasourceRpc::Datasource

Inherits:
ForestAdminDatasourceToolkit::Datasource
  • Object
show all
Includes:
Utils
Defined in:
lib/forest_admin_datasource_rpc/datasource.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, introspection) ⇒ Datasource

Returns a new instance of Datasource.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/forest_admin_datasource_rpc/datasource.rb', line 5

def initialize(options, introspection)
  super()

  ForestAdminRpcAgent::Facades::Container.logger.log(
    'Info',
    "Building Rpc Datasource with #{introspection[:collections].length} " \
    "collections and #{introspection[:charts].length} charts."
  )

  introspection[:collections].each do |schema|
    add_collection(Collection.new(self, schema[:name], options, schema))
  end

  @options = options
  @charts = introspection[:charts]
  @rpc_relations = introspection[:rpc_relations]

  @schema = { charts: @charts }
end

Instance Method Details

#render_chart(caller, name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/forest_admin_datasource_rpc/datasource.rb', line 25

def render_chart(caller, name)
  client = RpcClient.new(@options[:uri], ForestAdminRpcAgent::Facades::Container.cache(:auth_secret))
  url = 'forest/rpc/datasource-chart'

  ForestAdminRpcAgent::Facades::Container.logger.log(
    'Debug',
    "Forwarding datasource chart '#{name}' call to the Rpc agent on #{url}."
  )

  client.call_rpc(url, method: :post, payload: { chart: name, caller: caller.to_h })
end