Class: ScopedSearch::Definition
- Inherits:
-
Object
- Object
- ScopedSearch::Definition
- Defined in:
- lib/scoped_search/definition.rb
Defined Under Namespace
Classes: Field
Constant Summary collapse
- NUMBER_REGXP =
/^\-?\d+(\.\d+)?$/
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#unique_fields ⇒ Object
readonly
Returns the value of attribute unique_fields.
Instance Method Summary collapse
- #default_fields ⇒ Object
- #default_fields_for(value, operator = nil) ⇒ Object
- #define(options) ⇒ Object
-
#initialize(klass) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(klass) ⇒ Definition
Returns a new instance of Definition.
80 81 82 83 84 85 86 87 |
# File 'lib/scoped_search/definition.rb', line 80 def initialize(klass) @klass = klass @fields = {} @unique_fields = [] setup_adapter! unless klass.connection.nil? register_named_scope! unless klass.respond_to?(:search_for) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
78 79 80 |
# File 'lib/scoped_search/definition.rb', line 78 def fields @fields end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
78 79 80 |
# File 'lib/scoped_search/definition.rb', line 78 def klass @klass end |
#unique_fields ⇒ Object (readonly)
Returns the value of attribute unique_fields.
78 79 80 |
# File 'lib/scoped_search/definition.rb', line 78 def unique_fields @unique_fields end |
Instance Method Details
#default_fields ⇒ Object
101 102 103 |
# File 'lib/scoped_search/definition.rb', line 101 def default_fields unique_fields.reject { |field| field.only_explicit } end |
#default_fields_for(value, operator = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/scoped_search/definition.rb', line 91 def default_fields_for(value, operator = nil) # Use the value to detect column_types = [] column_types += [:string, :text] if [nil, :like, :unlike, :ne, :eq].include?(operator) column_types += [:integer, :double, :float, :decimal] if value =~ NUMBER_REGXP column_types += [:datetime, :date, :timestamp] if ScopedSearch::QueryBuilder.parse_temporal(value) default_fields.select { |field| column_types.include?(field.type) } end |