Class: AdminData::Search::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_data/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dbbaseObject

Returns the value of attribute dbbase.



45
46
47
# File 'lib/admin_data/search.rb', line 45

def dbbase
  @dbbase
end

#errorObject

Returns the value of attribute error.



45
46
47
# File 'lib/admin_data/search.rb', line 45

def error
  @error
end

#fieldObject

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

Parameters:

  • value

    the value to set the attribute operands to.



45
46
47
# File 'lib/admin_data/search.rb', line 45

def operands=(value)
  @operands = value
end

#operatorObject

Returns the value of attribute operator.



45
46
47
# File 'lib/admin_data/search.rb', line 45

def operator
  @operator
end

#table_nameObject

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_conditionObject



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

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/admin_data/search.rb', line 109

def valid?
  @error = nil
  @error = validate
  @error.blank?
end