Class: ForestAdminDatasourceMambuPayments::Query::ConditionTreeTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/forest_admin_datasource_mambu_payments/query/condition_tree_translator.rb

Overview

Translates a Forest condition tree into a hash of Numeral query params.

The previous version of ‘fetch_records` short-circuited on `id` and otherwise sent an unfiltered list — silently producing wrong counts and missing rows whenever the UI applied a non-id predicate. This translator raises `UnsupportedOperatorError` for anything it cannot map, so the failure mode is “loud error” rather than “wrong data”.

Each collection declares its server-filterable fields via ‘api_filters`:

{ 'connected_account_id' => { ops: [EQUAL, IN], param: 'connected_account_id' } }

‘param` defaults to the field name. EQUAL emits a scalar value, IN emits an Array (the client joins arrays with commas — see `Client#normalize_params`). Top-level OR aggregation is rejected: Numeral list endpoints have no general OR support, so silently translating “A or B” to “A and B” would be wrong in both directions.

Constant Summary collapse

Operators =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Operators
Branch =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes::ConditionTreeBranch
Leaf =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes::ConditionTreeLeaf

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_filters) ⇒ ConditionTreeTranslator

Returns a new instance of ConditionTreeTranslator.



31
32
33
# File 'lib/forest_admin_datasource_mambu_payments/query/condition_tree_translator.rb', line 31

def initialize(api_filters)
  @api_filters = api_filters || {}
end

Class Method Details

.call(condition_tree, api_filters: {}) ⇒ Object



25
26
27
28
29
# File 'lib/forest_admin_datasource_mambu_payments/query/condition_tree_translator.rb', line 25

def self.call(condition_tree, api_filters: {})
  return {} if condition_tree.nil?

  new(api_filters).translate(condition_tree)
end

Instance Method Details

#translate(node) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/forest_admin_datasource_mambu_payments/query/condition_tree_translator.rb', line 35

def translate(node)
  case node
  when Branch then translate_branch(node)
  when Leaf   then translate_leaf(node)
  else
    raise UnsupportedOperatorError, "Unknown condition node: #{node.class}"
  end
end