Class: Babik::QuerySet::Aggregation
- Inherits:
-
Object
- Object
- Babik::QuerySet::Aggregation
- Defined in:
- lib/babik/queryset/components/aggregation.rb
Overview
A set of aggregation operations
Instance Attribute Summary collapse
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, functions) ⇒ Aggregation
constructor
Construct a new aggregation.
-
#left_joins_by_alias ⇒ Hash{alias: Babik::QuerySet::Join}
Return the joins grouped by alias.
-
#sql ⇒ String
Return aggregation SQL.
Constructor Details
#initialize(model, functions) ⇒ Aggregation
Construct a new aggregation
15 16 17 18 19 20 21 |
# File 'lib/babik/queryset/components/aggregation.rb', line 15 def initialize(model, functions) @model = model @functions = [] functions.each do |field_name, function| @functions << function.prepare(@model, field_name) end end |
Instance Attribute Details
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
10 11 12 |
# File 'lib/babik/queryset/components/aggregation.rb', line 10 def functions @functions end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/babik/queryset/components/aggregation.rb', line 10 def model @model end |
Instance Method Details
#left_joins_by_alias ⇒ Hash{alias: Babik::QuerySet::Join}
Return the joins grouped by alias
25 26 27 28 29 30 31 |
# File 'lib/babik/queryset/components/aggregation.rb', line 25 def left_joins_by_alias left_joins_by_alias = {} @functions.each do |function| left_joins_by_alias.merge!(function.left_joins_by_alias) end left_joins_by_alias end |
#sql ⇒ String
Return aggregation SQL
35 36 37 |
# File 'lib/babik/queryset/components/aggregation.rb', line 35 def sql @functions.map(&:sql).join(', ') end |