Sha256: a52add9c1d9d22c0df9e47f8a24669cf0f869751a152950c03cd45c43517f075

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require "active_support/core_ext/module/delegation"
require "active_support/core_ext/hash/keys"

module PgSearch
  module Features
    class Feature
      def self.valid_options
        %i[only sort_only]
      end

      delegate :connection, :quoted_table_name, :to => :'@model'

      def initialize(query, options, all_columns, model, normalizer)
        @query = query
        @options = (options || {}).assert_valid_keys(self.class.valid_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

4 entries across 4 versions & 1 rubygems

Version Path
pg_search-2.1.3 lib/pg_search/features/feature.rb
pg_search-2.1.2 lib/pg_search/features/feature.rb
pg_search-2.1.1 lib/pg_search/features/feature.rb
pg_search-2.1.0 lib/pg_search/features/feature.rb