class ArtirixDataModels::AggregationsFactory
Constants
- DEFAULT_COLLECTION_CLASS_NAME
Public Class Methods
new()
click to toggle source
FACTORY INSTANCE
# File lib/artirix_data_models/aggregations_factory.rb, line 15 def initialize @_loaders = Hash.new { |h, k| h[k] = {} } setup_config end
sorted_aggregation_class_based_on_index_on(index_array)
click to toggle source
AGGREGATION CLASS BUILDING
# 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
Public Instance Methods
aggregation_from_json(definition, value_class: Aggregation::Value, aggregation_class: Aggregation)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
AGGREGATION BUILDING
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
SETUP AND CONFIG MANAGEMENT
# File lib/artirix_data_models/aggregations_factory.rb, line 22 def setup_config # To be Extended end
Private Instance Methods
normalise_aggregations_data(raw_aggs)
click to toggle source
# File lib/artirix_data_models/aggregations_factory.rb, line 75 def normalise_aggregations_data(raw_aggs) RawAggregationDataNormaliser.new(self, raw_aggs).normalise end