Class: ScopedSearch::Definition::Field
- Inherits:
-
Object
- Object
- ScopedSearch::Definition::Field
- Defined in:
- lib/scoped_search/definition.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#only_explicit ⇒ Object
readonly
Returns the value of attribute only_explicit.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Instance Method Summary collapse
-
#column ⇒ Object
Find the relevant column definition in the AR class.
- #date? ⇒ Boolean
- #datetime? ⇒ Boolean
-
#default_operator ⇒ Object
Returns the default search operator for this field.
-
#initialize(definition, options = {}) ⇒ Field
constructor
A new instance of Field.
- #klass ⇒ Object
- #numerical? ⇒ Boolean
- #temporal? ⇒ Boolean
- #textual? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(definition, options = {}) ⇒ Field
Returns a new instance of Field.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/scoped_search/definition.rb', line 54 def initialize(definition, = {}) @definition = definition case when Symbol, String @field = field.to_sym when Hash @field = .delete(:on) # Set attributes from options hash @relation = [:in] @only_explicit = !![:only_explicit] @default_operator = [:default_operator] if .has_key?(:default_operator) end # Store this field is the field array definition.fields[@field] ||= self definition.unique_fields << self # Store definition for alias / aliases as well definition.fields[[:alias]] ||= self if [:alias] [:aliases].each { |al| definition.fields[al] ||= self } if [:aliases] end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
7 8 9 |
# File 'lib/scoped_search/definition.rb', line 7 def definition @definition end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/scoped_search/definition.rb', line 7 def field @field end |
#only_explicit ⇒ Object (readonly)
Returns the value of attribute only_explicit.
7 8 9 |
# File 'lib/scoped_search/definition.rb', line 7 def only_explicit @only_explicit end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
7 8 9 |
# File 'lib/scoped_search/definition.rb', line 7 def relation @relation end |
Instance Method Details
#column ⇒ Object
Find the relevant column definition in the AR class
18 19 20 |
# File 'lib/scoped_search/definition.rb', line 18 def column klass.columns_hash[field.to_s] end |
#date? ⇒ Boolean
30 31 32 |
# File 'lib/scoped_search/definition.rb', line 30 def date? type == :date end |
#datetime? ⇒ Boolean
26 27 28 |
# File 'lib/scoped_search/definition.rb', line 26 def datetime? [:datetime, :time, :timestamp].include?(type) end |
#default_operator ⇒ Object
Returns the default search operator for this field.
47 48 49 50 51 52 |
# File 'lib/scoped_search/definition.rb', line 47 def default_operator @default_operator ||= case type when :string, :text then :like else :eq end end |
#klass ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/scoped_search/definition.rb', line 9 def klass if relation definition.klass.reflections[relation].klass else definition.klass end end |
#numerical? ⇒ Boolean
38 39 40 |
# File 'lib/scoped_search/definition.rb', line 38 def numerical? [:integer, :double, :float, :decimal].include?(type) end |
#temporal? ⇒ Boolean
34 35 36 |
# File 'lib/scoped_search/definition.rb', line 34 def temporal? datetime? || date? end |
#textual? ⇒ Boolean
42 43 44 |
# File 'lib/scoped_search/definition.rb', line 42 def textual? [:string, :text].include?(type) end |
#type ⇒ Object
22 23 24 |
# File 'lib/scoped_search/definition.rb', line 22 def type column.type end |