Class: EagerGroup::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_group/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association, aggregate_function, column_name, scope) ⇒ Definition

Returns a new instance of Definition.



7
8
9
10
11
12
# File 'lib/eager_group/definition.rb', line 7

def initialize(association, aggregate_function, column_name, scope)
  @association = association
  @aggregate_function = aggregate_function
  @column_name = column_name
  @scope = scope
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



5
6
7
# File 'lib/eager_group/definition.rb', line 5

def association
  @association
end

#column_nameObject (readonly)

Returns the value of attribute column_name.



5
6
7
# File 'lib/eager_group/definition.rb', line 5

def column_name
  @column_name
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/eager_group/definition.rb', line 5

def scope
  @scope
end

Instance Method Details

#aggregation_functionObject



14
15
16
17
18
19
# File 'lib/eager_group/definition.rb', line 14

def aggregation_function
  return :maximum if @aggregate_function.to_sym == :last_object
  return :minimum if @aggregate_function.to_sym == :first_object

  @aggregate_function
end

#default_valueObject



25
26
27
# File 'lib/eager_group/definition.rb', line 25

def default_value
  %i[first_object last_object].include?(@aggregate_function.to_sym) ? nil : 0
end

#need_load_objectObject



21
22
23
# File 'lib/eager_group/definition.rb', line 21

def need_load_object
  %i[first_object last_object].include?(@aggregate_function.to_sym)
end