Sha256: edb5c6995dfe82ce7b66b9f1700d2cc114785321fb5d9624444529459abcf572

Contents?: true

Size: 793 Bytes

Versions: 4

Compression:

Stored size: 793 Bytes

Contents

module Searchgasm
  module Condition
    class IsBlank < Base
      self.ignore_blanks = false
      self.type_cast_value = false
      
      class << self
        def aliases_for_column(column)
          ["#{column.name}_blank"]
        end
      end
      
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
searchgasm-1.1.2 lib/searchgasm/condition/is_blank.rb
searchgasm-1.2.0 lib/searchgasm/condition/is_blank.rb
searchgasm-1.2.1 lib/searchgasm/condition/is_blank.rb
searchgasm-1.1.3 lib/searchgasm/condition/is_blank.rb