Class: PgSearch::Configuration::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_search/configuration/column.rb

Direct Known Subclasses

ForeignColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_name, weight, model) ⇒ Column

Returns a new instance of Column.



10
11
12
13
14
15
# File 'lib/pg_search/configuration/column.rb', line 10

def initialize(column_name, weight, model)
  @name = column_name.to_s
  @column_name = column_name
  @weight = weight
  @model = model
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/pg_search/configuration/column.rb', line 8

def name
  @name
end

#weightObject (readonly)

Returns the value of attribute weight.



8
9
10
# File 'lib/pg_search/configuration/column.rb', line 8

def weight
  @weight
end

Instance Method Details

#source_attributeObject

Physical source-column attribute, or the supplied trusted SQL literal. Foreign columns refer to the association table, not the search alias.



19
20
21
22
23
# File 'lib/pg_search/configuration/column.rb', line 19

def source_attribute
  return @column_name if @column_name.is_a?(Arel::Nodes::SqlLiteral)

  Arel::Attributes::Attribute.new(source_table, @name)
end

#to_arelObject

Composable search expression cast to text, with NULL mapped to "". Foreign columns use their derived search alias rather than the source.



27
# File 'lib/pg_search/configuration/column.rb', line 27

def to_arel = coalesce_to_blank_string(cast_to_text(attribute))