Class: ForestAdminDatasourceZendesk::Collections::BaseCollection

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

Direct Known Subclasses

Organization, Ticket, User

Constant Summary collapse

ColumnSchema =
ForestAdminDatasourceToolkit::Schema::ColumnSchema
Operators =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Operators
Leaf =
ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes::ConditionTreeLeaf
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datasource, name, custom_fields: [], searchable: true, countable: true, native_driver: nil) ⇒ BaseCollection

Template method: subclasses implement ‘define_schema` and `define_relations` as hooks; ordering between them, custom-field registration, and the search/count flags is owned here so collisions are always evaluated against the final native schema. A subclass can opt out of search/count by passing `searchable: false` / `countable: false` through `super`.



22
23
24
25
26
27
28
29
# File 'lib/forest_admin_datasource_zendesk/collections/base_collection.rb', line 22

def initialize(datasource, name, custom_fields: [], searchable: true, countable: true, native_driver: nil)
  super(datasource, name, native_driver)
  define_schema
  define_relations
  @custom_fields = add_custom_fields(custom_fields)
  enable_search if searchable
  enable_count if countable
end

Instance Attribute Details

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields.



14
15
16
# File 'lib/forest_admin_datasource_zendesk/collections/base_collection.rb', line 14

def custom_fields
  @custom_fields
end

Instance Method Details

#aggregate(caller, filter, aggregation, _limit = nil) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/forest_admin_datasource_zendesk/collections/base_collection.rb', line 31

def aggregate(caller, filter, aggregation, _limit = nil)
  unless aggregation.operation == 'Count' && aggregation.field.nil? && aggregation.groups.empty?
    raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
          'Zendesk datasource only supports Count aggregation without groups.'
  end

  [{ 'value' => aggregate_count(caller, filter), 'group' => {} }]
end