module Aggregations::Helpers::AbstractAggregationHelper

A helper module for aggregations, defines sub aggregation attributes.

Public Instance Methods

abstract_agg_builder() click to toggle source

helper method to add abstract aggregation attributes to aggregation.

# File lib/aggregations/helpers/abstract_aggregation_helper.rb, line 8
def abstract_agg_builder
  builder = {}
  builder[:aggs] = build_sub_aggs_struct if @sub_aggregations.present?
  builder
end
sub_aggregation(sub_agg) click to toggle source

@param [AggregationQueryBuilderHelper] sub_agg : AggregationBuilders factory @return [AbstractAggregationHelper] : aggregation object

# File lib/aggregations/helpers/abstract_aggregation_helper.rb, line 16
def sub_aggregation(sub_agg)
  @sub_aggregations = [] if @sub_aggregations.nil?
  @sub_aggregations = @sub_aggregations.append(sub_agg)
  self
end
sub_aggregation_expr() click to toggle source

@return [AbstractAggregationHelper] : aggregation object

# File lib/aggregations/helpers/abstract_aggregation_helper.rb, line 23
def sub_aggregation_expr
  @sub_aggregations
end

Private Instance Methods

build_sub_aggs_struct() click to toggle source
# File lib/aggregations/helpers/abstract_aggregation_helper.rb, line 29
def build_sub_aggs_struct
  @sub_aggregations.each_with_object({}) do |ag, qr|
    qr.merge!(ag.attributes.query)
    qr
  end
end