Class: PgSearch::Configuration::Column
- Inherits:
-
Object
- Object
- PgSearch::Configuration::Column
- Defined in:
- lib/pg_search/configuration/column.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #alias ⇒ Object
- #foreign? ⇒ Boolean
- #full_name ⇒ Object
-
#initialize(column_name, weight, model, association = nil) ⇒ Column
constructor
A new instance of Column.
- #table ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(column_name, weight, model, association = nil) ⇒ Column
Returns a new instance of Column.
8 9 10 11 12 13 |
# File 'lib/pg_search/configuration/column.rb', line 8 def initialize(column_name, weight, model, association = nil) @column_name = column_name.to_s @weight = weight @model = model @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
6 7 8 |
# File 'lib/pg_search/configuration/column.rb', line 6 def association @association end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
6 7 8 |
# File 'lib/pg_search/configuration/column.rb', line 6 def weight @weight end |
Instance Method Details
#alias ⇒ Object
36 37 38 |
# File 'lib/pg_search/configuration/column.rb', line 36 def alias Configuration.alias(association.subselect_alias, @column_name) end |
#foreign? ⇒ Boolean
32 33 34 |
# File 'lib/pg_search/configuration/column.rb', line 32 def foreign? @association.present? end |
#full_name ⇒ Object
19 20 21 |
# File 'lib/pg_search/configuration/column.rb', line 19 def full_name "#{@model.connection.quote_table_name(table)}.#{@model.connection.quote_column_name(@column_name)}" end |
#table ⇒ Object
15 16 17 |
# File 'lib/pg_search/configuration/column.rb', line 15 def table foreign? ? @association.table_name : @model.table_name end |
#to_sql ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/pg_search/configuration/column.rb', line 23 def to_sql name = if foreign? "#{@association.subselect_alias}.#{self.alias}" else full_name end "coalesce(#{name}, '')" end |