Sha256: 10832b1f6b8f152c78ccdd5880dc33acbeb07e4743c014c9315f9724e934c573

Contents?: true

Size: 919 Bytes

Versions: 8

Compression:

Stored size: 919 Bytes

Contents

require "active_support/core_ext/module/delegation"

module PgSearch
  module Features
    class Feature
      delegate :connection, :quoted_table_name, :to => :'@model'

      def initialize(query, options, all_columns, model, normalizer)
        @query = query
        @options = options || {}
        @all_columns = all_columns
        @model = model
        @normalizer = normalizer
      end

      private

      attr_reader :query, :options, :all_columns, :model, :normalizer

      def document
        columns.map { |column| column.to_sql }.join(" || ' ' || ")
      end

      def columns
        if options[:only]
          all_columns.select do |column|
            Array.wrap(options[:only]).map(&:to_s).include? column.name
          end
        else
          all_columns
        end
      end

      def normalize(expression)
        normalizer.add_normalization(expression)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pg_search-1.0.3 lib/pg_search/features/feature.rb
pg_search-1.0.2 lib/pg_search/features/feature.rb
pg_search-1.0.1 lib/pg_search/features/feature.rb
pg_search-1.0.0 lib/pg_search/features/feature.rb
pg_search-0.7.9 lib/pg_search/features/feature.rb
pg_search-0.7.8 lib/pg_search/features/feature.rb
pg_search-0.7.7 lib/pg_search/features/feature.rb
pg_search-0.7.6 lib/pg_search/features/feature.rb