Class: Searchgasm::Condition::IsBlank

Inherits:
Base
  • Object
show all
Defined in:
lib/searchgasm/condition/is_blank.rb

Instance Attribute Summary

Attributes inherited from Base

#column, #klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

aliases_for_klass, comparable_column?, #condition_name, condition_name, #explicitly_set_value=, #explicitly_set_value?, ignore_blanks?, #initialize, #name, name_for_column, name_for_klass, #quote_column_name, #quote_table_name, #quoted_column_name, #quoted_table_name, #sanitize, string_column?, type_cast_value?, #value, #value=

Constructor Details

This class inherits a constructor from Searchgasm::Condition::Base

Class Method Details

.aliases_for_column(column) ⇒ Object



8
9
10
# File 'lib/searchgasm/condition/is_blank.rb', line 8

def aliases_for_column(column)
  ["#{column.name}_blank"]
end

Instance Method Details

#to_conditions(value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/searchgasm/condition/is_blank.rb', line 13

def to_conditions(value)
  # Some databases handle null values differently, let AR handle this
  if value == true || value == "true" || value == 1 || value == "1"
    "#{quoted_table_name}.#{quoted_column_name} is NULL or #{quoted_table_name}.#{quoted_column_name} = ''"
  elsif value == false || value == "false" || value == 0 || value == "0"
    "#{quoted_table_name}.#{quoted_column_name} is NOT NULL and #{quoted_table_name}.#{quoted_column_name} != ''"
  end
end