Class: Babik::Selection::Path::ForeignPath

Inherits:
Object
  • Object
show all
Defined in:
lib/babik/queryset/lib/selection/path/foreign_path.rb

Overview

Foreign path A foreign path is a succession of associations ending optionally in an operator if operator is not present, equal is supposed.

Direct Known Subclasses

ForeignSelection

Constant Summary collapse

RELATIONSHIP_SEPARATOR =
Babik::Selection::Config::RELATIONSHIP_SEPARATOR
OPERATOR_SEPARATOR =
Babik::Selection::Config::OPERATOR_SEPARATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, selection_path) ⇒ ForeignPath

Construct a foreign path A foreign path will be used with a value as a foreign selection to filter a model with foreign conditions

Parameters:

  • model (ActiveRecord::Base)

    model that is the object of the foreign path.

  • selection_path (String, Symbol)

    Association path with an operator. e.g.: posts::category__in author::posts::tags creation_at__date__gte



32
33
34
35
36
37
38
39
40
# File 'lib/babik/queryset/lib/selection/path/foreign_path.rb', line 32

def initialize(model, selection_path)
  @model = model
  @selection_path = selection_path.dup
  @association_path = selection_path.to_s.split(RELATIONSHIP_SEPARATOR)
  selection_path = @association_path.pop
  @selected_field, @operator = selection_path.split(OPERATOR_SEPARATOR)
  @operator ||= 'equal'
  _initialize_associations
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



17
18
19
# File 'lib/babik/queryset/lib/selection/path/foreign_path.rb', line 17

def model
  @model
end

#selected_fieldObject (readonly)

Returns the value of attribute selected_field.



17
18
19
# File 'lib/babik/queryset/lib/selection/path/foreign_path.rb', line 17

def selected_field
  @selected_field
end

#selection_pathObject (readonly)

Returns the value of attribute selection_path.



17
18
19
# File 'lib/babik/queryset/lib/selection/path/foreign_path.rb', line 17

def selection_path
  @selection_path
end

Instance Method Details

#_initialize_associationsObject

Initialize associations



43
44
45
46
# File 'lib/babik/queryset/lib/selection/path/foreign_path.rb', line 43

def _initialize_associations
  @association_chain = Babik::Association::ForeignAssociationChain.new(@model, @association_path, @selection_path)
  @association_joiner = Babik::QuerySet::Join::AssociationJoiner.new(@association_chain.associations)
end