Class: AdminData::Search::Term
- Inherits:
-
Object
- Object
- AdminData::Search::Term
- Defined in:
- lib/admin_data/search.rb
Instance Attribute Summary collapse
-
#dbbase ⇒ Object
Returns the value of attribute dbbase.
-
#error ⇒ Object
Returns the value of attribute error.
-
#field ⇒ Object
Returns the value of attribute field.
-
#operands ⇒ Object
writeonly
Sets the attribute operands.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
- #attribute_condition ⇒ Object
-
#initialize(klass, value, search_type) ⇒ Term
constructor
A new instance of Term.
- #valid? ⇒ Boolean
Constructor Details
#initialize(klass, value, search_type) ⇒ Term
Returns a new instance of Term.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/admin_data/search.rb', line 47 def initialize(klass, value, search_type) @table_name = klass.table_name compute_search_fields(value) adapter = AdminData.config.adapter_name.downcase if adapter =~ /postgresql/ self.dbbase = PostgresqlSpecific.new(@operands, table_name, field, operator) elsif adapter =~ /oracle/ self.dbbase = OracleSpecific.new(@operands, table_name, field, operator) else self.dbbase = Dbbase.new(@operands, table_name, field, operator) end end |
Instance Attribute Details
#dbbase ⇒ Object
Returns the value of attribute dbbase.
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def dbbase @dbbase end |
#error ⇒ Object
Returns the value of attribute error.
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def error @error end |
#field ⇒ Object
Returns the value of attribute field.
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def field @field end |
#operands=(value) ⇒ Object
Sets the attribute operands
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def operands=(value) @operands = value end |
#operator ⇒ Object
Returns the value of attribute operator.
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def operator @operator end |
#table_name ⇒ Object
Returns the value of attribute table_name.
45 46 47 |
# File 'lib/admin_data/search.rb', line 45 def table_name @table_name end |
Instance Method Details
#attribute_condition ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/admin_data/search.rb', line 61 def attribute_condition return if valid? && operand_required? && operands.blank? case operator when 'contains' ["#{sql_field_name} #{like_operator} ?","%#{operands}%"] when 'is_exactly' ["#{sql_field_name} = ?", operands] when 'does_not_contain' ["#{sql_field_name} IS NULL OR #{sql_field_name} NOT #{like_operator} ?","%#{operands}%"] when 'is_false' ["#{sql_field_name} = ?",false] when 'is_true' ["#{sql_field_name} = ?",true] when 'is_null' ["#{sql_field_name} IS NULL"] when 'is_not_null' ["#{sql_field_name} IS NOT NULL"] when 'is_on' ["#{sql_field_name} >= ? AND #{sql_field_name} < ?", values_after_cast.beginning_of_day, values_after_cast.end_of_day] when 'is_on_or_before_date' ["#{sql_field_name} <= ?",values_after_cast.end_of_day] when 'is_on_or_after_date' ["#{sql_field_name} >= ?",values_after_cast.beginning_of_day] when 'is_equal_to' ["#{sql_field_name} = ?",values_after_cast] when 'greater_than' ["#{sql_field_name} > ?",values_after_cast] when 'less_than' ["#{sql_field_name} < ?",values_after_cast] else # it means user did not select anything in operator. Ignore it. end end |
#valid? ⇒ Boolean
109 110 111 112 113 |
# File 'lib/admin_data/search.rb', line 109 def valid? @error = nil @error = validate @error.blank? end |