Class: Mincer::PgSearch::SearchEngines::Base
- Inherits:
-
Object
- Object
- Mincer::PgSearch::SearchEngines::Base
- Includes:
- Mincer::Processors::Helpers
- Defined in:
- lib/mincer/processors/pg_search/search_engines/base.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#search_statements ⇒ Object
readonly
Returns the value of attribute search_statements.
Instance Method Summary collapse
- #arel_group(sql_string = nil) ⇒ Object
-
#engine_sym ⇒ Object
Redefine this method in subclass if your engine name does not match class.
-
#initialize(args, search_statements) ⇒ Base
constructor
A new instance of Base.
- #prepared_search_statements ⇒ Object
- #quote(string) ⇒ Object
- #rank ⇒ Object
- #sanitize_column(term, sanitizers) ⇒ Object
- #sanitize_string(term, sanitizers) ⇒ Object
- #sanitize_string_quoted(term, sanitizers) ⇒ Object
- #search_engine_statements ⇒ Object
Methods included from Mincer::Processors::Helpers
Constructor Details
#initialize(args, search_statements) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 8 def initialize(args, search_statements) @args, @search_statements = ::ActiveSupport::HashWithIndifferentAccess.new(args), search_statements end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 6 def args @args end |
#search_statements ⇒ Object (readonly)
Returns the value of attribute search_statements.
6 7 8 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 6 def search_statements @search_statements end |
Instance Method Details
#arel_group(sql_string = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 12 def arel_group(sql_string = nil) sql_string = yield if block_given? arel_query = sql_string.is_a?(String) ? Arel.sql(sql_string) : sql_string return arel_query if arel_query.is_a?(Arel::Nodes::Grouping) Arel::Nodes::Grouping.new(arel_query) end |
#engine_sym ⇒ Object
Redefine this method in subclass if your engine name does not match class
45 46 47 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 45 def engine_sym @engine_sym ||= self.class.name.to_s.demodulize.underscore.to_sym end |
#prepared_search_statements ⇒ Object
37 38 39 40 41 42 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 37 def prepared_search_statements @prepared_search_statements ||= search_engine_statements.map do |search_statement| search_statement.pattern = args[search_statement.param_name] search_statement.pattern.present? ? search_statement : nil end.compact end |
#quote(string) ⇒ Object
54 55 56 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 54 def quote(string) Mincer::Processors::PgSearch::Sanitizer.quote(string) end |
#rank ⇒ Object
49 50 51 52 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 49 def rank #Must be implemented in subclasses nil end |
#sanitize_column(term, sanitizers) ⇒ Object
19 20 21 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 19 def sanitize_column(term, sanitizers) ::Mincer::Processors::PgSearch::Sanitizer.sanitize_column(term, sanitizers) end |
#sanitize_string(term, sanitizers) ⇒ Object
23 24 25 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 23 def sanitize_string(term, sanitizers) ::Mincer::Processors::PgSearch::Sanitizer.sanitize_string(term, sanitizers) end |
#sanitize_string_quoted(term, sanitizers) ⇒ Object
27 28 29 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 27 def sanitize_string_quoted(term, sanitizers) ::Mincer::Processors::PgSearch::Sanitizer.sanitize_string_quoted(term, sanitizers) end |
#search_engine_statements ⇒ Object
31 32 33 34 35 |
# File 'lib/mincer/processors/pg_search/search_engines/base.rb', line 31 def search_engine_statements @search_engine_statements ||= self.search_statements.select do |search_statement| search_statement.[:engines].try(:include?, engine_sym) end end |