Sha256: 7addc917136851aff248cd0665f69944f90f6138e460eb32507f165054e2935e

Contents?: true

Size: 944 Bytes

Versions: 2

Compression:

Stored size: 944 Bytes

Contents

require 'digest'

module PgSearch
  class Configuration
    class Column
      attr_reader :weight, :association

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

      def table
        foreign? ? @association.table_name : @model.table_name
      end

      def full_name
        "#{@model.connection.quote_table_name(table)}.#{@model.connection.quote_column_name(@column_name)}"
      end

      def to_sql
        name = if foreign?
                 "#{@association.subselect_alias}.#{self.alias}"
               else
                 full_name
               end
        "coalesce(#{name}::text, '')"
      end

      def foreign?
        @association.present?
      end

      def alias
        Configuration.alias(association.subselect_alias, @column_name)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_search-0.5.1 lib/pg_search/configuration/column.rb
pg_search-0.5 lib/pg_search/configuration/column.rb