module Silly::QueryOperators

Public Class Methods

equals(attribute, value) click to toggle source
# File lib/silly/query_operators.rb, line 20
def self.equals(attribute, value)
  case attribute
  when Array
    attribute.include?(value)
  else
    attribute == value
  end
end
exclude(attribute, value) click to toggle source
# File lib/silly/query_operators.rb, line 38
def self.exclude(attribute, value)
  case attribute
  when Array
    attribute.each{ |a| return false if (a =~ value) }
  else
    !(attribute =~ value)
  end
end
execute(attribute, value) click to toggle source
# File lib/silly/query_operators.rb, line 3
def self.execute(attribute, value)
  if value.is_a?(Hash)
    type, value = value.to_a.first
  else
    type = "$equals"
    value = value.is_a?(Symbol) ? value.to_s : value
  end

  command = type[1, type.size]

  __send__(command, attribute, value)
end
exists(attribute, value) click to toggle source
# File lib/silly/query_operators.rb, line 16
def self.exists(attribute, value)
  !!attribute == !!value
end
ne(attribute, value) click to toggle source
# File lib/silly/query_operators.rb, line 29
def self.ne(attribute, value)
  case attribute
  when Array
    !attribute.include?(value)
  else
    attribute != value
  end
end