Skip to content

Commit

Permalink
Merge pull request #215 from janko-m/assert-feature-options
Browse files Browse the repository at this point in the history
Assert valid options for features
  • Loading branch information
nertzy committed May 15, 2015
2 parents cf432bd + 6b8e49c commit 3031fd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pg_search/features/feature.rb
@@ -1,13 +1,18 @@
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/hash/keys"

module PgSearch
module Features
class Feature
def self.valid_options
[:only, :sort_only]
end

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

def initialize(query, options, all_columns, model, normalizer)
@query = query
@options = options || {}
@options = (options || {}).assert_valid_keys(self.class.valid_options)
@all_columns = all_columns
@model = model
@normalizer = normalizer
Expand Down
3 changes: 3 additions & 0 deletions lib/pg_search/features/trigram.rb
@@ -1,6 +1,9 @@
module PgSearch
module Features
class Trigram < Feature
def self.valid_options
super + [:threshold]
end

def conditions
if options[:threshold]
Expand Down
4 changes: 4 additions & 0 deletions lib/pg_search/features/tsearch.rb
Expand Up @@ -4,6 +4,10 @@
module PgSearch
module Features
class TSearch < Feature
def self.valid_options
super + [:dictionary, :prefix, :negation, :any_word, :normalization, :tsvector_column]
end

def initialize(*args)
super

Expand Down

0 comments on commit 3031fd3

Please sign in to comment.