Class: Babik::Selection::Path::LocalPath

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

Overview

Local path

Direct Known Subclasses

LocalSelection

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, selection_path) ⇒ LocalPath

Construct a local field path

Parameters:

  • model (ActiveRecord::Base)

    model whose field will be used.

  • selection_path (String)

    selection path. Of the form <field>__<operator>. e.g. first_name__equal, stars__gt If no operator is given (first_name), ‘equal’ will be used.



19
20
21
22
23
24
25
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 19

def initialize(model, selection_path)
  @model = model
  @selection_path = selection_path.dup
  @selected_field, @operator, @secondary_operator = @selection_path.to_s.split(OPERATOR_SEPARATOR)
  # By default, if no operator is given, 'equal' will be used
  @operator ||= 'equal'
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 13

def model
  @model
end

#operatorObject (readonly)

Returns the value of attribute operator.



13
14
15
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 13

def operator
  @operator
end

#secondary_operatorObject (readonly)

Returns the value of attribute secondary_operator.



13
14
15
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 13

def secondary_operator
  @secondary_operator
end

#selected_fieldObject (readonly)

Returns the value of attribute selected_field.



13
14
15
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 13

def selected_field
  @selected_field
end

#selection_pathObject (readonly)

Returns the value of attribute selection_path.



13
14
15
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 13

def selection_path
  @selection_path
end

Instance Method Details

#left_joins_by_aliasHash

A local selection has no related left joins

Returns:

  • (Hash)

    Empty hash.



37
38
39
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 37

def left_joins_by_alias
  {}
end

#target_aliasString

Return the target table alias. That is alias of the model table. For the moment, actually, return the name of this model’s table.

Returns:

  • (String)

    alias of the model table.



31
32
33
# File 'lib/babik/queryset/lib/selection/path/local_path.rb', line 31

def target_alias
  @model.table_name
end