Class: ArtirixDataModels::AggregationsFactory
- Inherits:
-
Object
- Object
- ArtirixDataModels::AggregationsFactory
- Includes:
- WithDAORegistry
- Defined in:
- lib/artirix_data_models/aggregations_factory.rb
Defined Under Namespace
Modules: SortedBucketsAggregationClassFactory
Constant Summary collapse
- DEFAULT_COLLECTION_CLASS_NAME =
''.freeze
Constants included from WithDAORegistry
WithDAORegistry::DEFAULT_DAO_REGISTRY_LOADER
Instance Attribute Summary
Attributes included from WithDAORegistry
Class Method Summary collapse
-
.sorted_aggregation_class_based_on_index_on(index_array) ⇒ Object
AGGREGATION CLASS BUILDING.
Instance Method Summary collapse
- #aggregation_from_json(definition, value_class: Aggregation::Value, aggregation_class: Aggregation) ⇒ Object
- #build_all_from_raw_data(raw, collection_class = nil) ⇒ Object
-
#build_from_json(aggregation, collection_class = nil) ⇒ Object
AGGREGATION BUILDING.
- #default_loader ⇒ Object
- #get_loader(aggregation_name, collection_class) ⇒ Object
-
#initialize ⇒ AggregationsFactory
constructor
FACTORY INSTANCE.
- #set_loader(aggregation_name, collection_class = nil, loader = nil, &block) ⇒ Object
-
#setup_config ⇒ Object
SETUP AND CONFIG MANAGEMENT.
Methods included from WithDAORegistry
#dao_registry, #dao_registry=, #default_dao_registry, loader_or_registry_or_default, #set_dao_registry, #set_dao_registry_and_loader, #set_dao_registry_loader, #set_default_dao_registry_loader
Constructor Details
#initialize ⇒ AggregationsFactory
FACTORY INSTANCE
15 16 17 18 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 15 def initialize @_loaders = Hash.new { |h, k| h[k] = {} } setup_config end |
Class Method Details
.sorted_aggregation_class_based_on_index_on(index_array) ⇒ Object
AGGREGATION CLASS BUILDING
9 10 11 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 9 def self.sorted_aggregation_class_based_on_index_on(index_array) SortedBucketsAggregationClassFactory.build_class_based_on_index_on(index_array) end |
Instance Method Details
#aggregation_from_json(definition, value_class: Aggregation::Value, aggregation_class: Aggregation) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 62 def aggregation_from_json(definition, value_class: Aggregation::Value, aggregation_class: Aggregation) builder_params = { aggregations_factory: self, definition: definition, aggregation_class: aggregation_class, value_class: value_class, } AggregationBuilder.new(builder_params).build end |
#build_all_from_raw_data(raw, collection_class = nil) ⇒ Object
57 58 59 60 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 57 def build_all_from_raw_data(raw, collection_class = nil) normalised = normalise_aggregations_data(raw) normalised.map { |definition| build_from_json definition, collection_class } end |
#build_from_json(aggregation, collection_class = nil) ⇒ Object
AGGREGATION BUILDING
53 54 55 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 53 def build_from_json(aggregation, collection_class = nil) get_loader(aggregation[:name], collection_class).call aggregation end |
#default_loader ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 36 def default_loader aggregations_factory = self proc { |definition| aggregations_factory.aggregation_from_json definition, value_class: Aggregation::Value, aggregation_class: Aggregation } end |
#get_loader(aggregation_name, collection_class) ⇒ Object
45 46 47 48 49 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 45 def get_loader(aggregation_name, collection_class) @_loaders[collection_class.to_s][aggregation_name.to_s] || @_loaders[DEFAULT_COLLECTION_CLASS_NAME][aggregation_name.to_s] || default_loader end |
#set_loader(aggregation_name, collection_class = nil, loader = nil, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 26 def set_loader(aggregation_name, collection_class = nil, loader = nil, &block) if block @_loaders[collection_class.to_s][aggregation_name.to_s] = block elsif loader.respond_to? :call @_loaders[collection_class.to_s][aggregation_name.to_s] = loader else raise ArgumentError, "no block and no loader given for key #{key}" end end |
#setup_config ⇒ Object
SETUP AND CONFIG MANAGEMENT
22 23 24 |
# File 'lib/artirix_data_models/aggregations_factory.rb', line 22 def setup_config # To be Extended end |