Class: ForestAdminDatasourceMambuPayments::Collections::BaseCollection

Inherits:
ForestAdminDatasourceToolkit::Collection
  • Object
show all
Defined in:
lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb

Overview

Shared read path (list / id-lookup / pagination / relation embedding) for every Numeral-backed collection. Subclasses declare their REST resource via ‘client_resource` and implement `serialize`; `collection_filters` lists the server-filterable fields and `reconcile_filter_operators!` narrows each column’s advertised operators to what the API can serve. rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: Embed

Constant Summary collapse

ColumnSchema =
ForestAdminDatasourceToolkit::Schema::ColumnSchema
Operators =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Operators
Leaf =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes::ConditionTreeLeaf
ForestException =
ForestAdminDatasourceToolkit::Exceptions::ForestException
STRING_OPS =
[Operators::EQUAL, Operators::NOT_EQUAL, Operators::IN, Operators::NOT_IN,
Operators::PRESENT, Operators::BLANK].freeze
NUMBER_OPS =
(STRING_OPS + [Operators::GREATER_THAN, Operators::LESS_THAN]).freeze
DATE_OPS =
[Operators::EQUAL, Operators::BEFORE, Operators::AFTER,
Operators::PRESENT, Operators::BLANK].freeze
BOOL_OPS =
[Operators::EQUAL, Operators::NOT_EQUAL,
Operators::PRESENT, Operators::BLANK].freeze
ID_OPS =

The id column is addressable (detail views, record selection) but the Numeral list endpoints have NO ‘id`/`ids` filter, so it is served by the find-by-id short-circuit (extract_id_lookup) and deliberately kept OUT of api_filters — a combined `id AND <field>` predicate raises loudly rather than silently sending an ignored param.

[Operators::EQUAL, Operators::IN].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.resource_pluralObject

Returns the value of attribute resource_plural.



31
32
33
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 31

def resource_plural
  @resource_plural
end

.resource_singularObject

Returns the value of attribute resource_singular.



31
32
33
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 31

def resource_singular
  @resource_singular
end

Class Method Details

.client_resource(singular, plural = nil) ⇒ Object

Declares the Numeral REST resource, wiring the read path to the matching ‘list_*` / `find_*` client methods.



36
37
38
39
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 36

def self.client_resource(singular, plural = nil)
  self.resource_singular = singular.to_s
  self.resource_plural = (plural || "#{singular}s").to_s
end

Instance Method Details

#aggregate(_caller, _filter, _aggregation, _limit = nil) ⇒ Object

Numeral exposes no count/aggregate endpoint and paginates by cursor, so there is no way to count matching records without scanning every page. Collections are therefore declared non-countable (no ‘enable_count`) and Forest never requests an aggregation; this guard makes the unsupported path explicit rather than returning a wrong number.

Raises:



53
54
55
56
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 53

def aggregate(_caller, _filter, _aggregation, _limit = nil)
  raise ForestException,
        'Mambu Payments collections are not countable: Numeral exposes no count endpoint.'
end

#fetch_by_ids(ids) ⇒ Object

Per-id find_* (Numeral has no batch id filter); public for cross-collection embed.



59
60
61
62
63
64
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 59

def fetch_by_ids(ids)
  ids = Array(ids).reject { |id| id.to_s.empty? }.uniq
  return [] if ids.empty?

  ids.filter_map { |id| client_find(id) }
end

#list(_caller, filter, projection) ⇒ Object



41
42
43
44
45
46
# File 'lib/forest_admin_datasource_mambu_payments/collections/base_collection.rb', line 41

def list(_caller, filter, projection)
  records = fetch_records(filter)
  rows = records.map { |r| project(serialize(r), projection) }
  embed_relations(rows, records, projection)
  rows
end