Module: Silly::QueryOperators

Defined in:
lib/silly/query_operators.rb

Class Method Summary collapse

Class Method Details

.equals(attribute, value) ⇒ Object



20
21
22
23
24
25
26
27
# 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) ⇒ Object



38
39
40
41
42
43
44
45
# 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) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



16
17
18
# File 'lib/silly/query_operators.rb', line 16

def self.exists(attribute, value)
  !!attribute == !!value
end

.ne(attribute, value) ⇒ Object



29
30
31
32
33
34
35
36
# 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