Class: Perpetuity::MongoDB::QueryExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/mongodb/query_expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, comparator, value) ⇒ QueryExpression

Returns a new instance of QueryExpression.



9
10
11
12
13
14
15
# File 'lib/perpetuity/mongodb/query_expression.rb', line 9

def initialize attribute, comparator, value
  @attribute = attribute
  @comparator = comparator
  @value = value

  @attribute = @attribute.to_sym if @attribute.respond_to? :to_sym
end

Instance Attribute Details

#comparatorObject

Returns the value of attribute comparator.



7
8
9
# File 'lib/perpetuity/mongodb/query_expression.rb', line 7

def comparator
  @comparator
end

Instance Method Details

#&(other) ⇒ Object



61
62
63
# File 'lib/perpetuity/mongodb/query_expression.rb', line 61

def & other
  QueryIntersection.new(self, other)
end

#equalsObject



21
22
23
# File 'lib/perpetuity/mongodb/query_expression.rb', line 21

def equals
  { @attribute => @value }
end

#function(func) ⇒ Object



25
26
27
# File 'lib/perpetuity/mongodb/query_expression.rb', line 25

def function func
  { @attribute => { func => @value } }
end

#greater_thanObject



37
38
39
# File 'lib/perpetuity/mongodb/query_expression.rb', line 37

def greater_than
  function '$gt'
end

#gteObject



41
42
43
# File 'lib/perpetuity/mongodb/query_expression.rb', line 41

def gte
  function '$gte'
end

#inObject



49
50
51
# File 'lib/perpetuity/mongodb/query_expression.rb', line 49

def in
  function '$in'
end

#less_thanObject



29
30
31
# File 'lib/perpetuity/mongodb/query_expression.rb', line 29

def less_than
  function '$lt'
end

#lteObject



33
34
35
# File 'lib/perpetuity/mongodb/query_expression.rb', line 33

def lte
  function '$lte'
end

#matchesObject



53
54
55
# File 'lib/perpetuity/mongodb/query_expression.rb', line 53

def matches
  { @attribute => @value }
end

#not_equalObject



45
46
47
# File 'lib/perpetuity/mongodb/query_expression.rb', line 45

def not_equal
  function '$ne'
end

#to_dbObject



17
18
19
# File 'lib/perpetuity/mongodb/query_expression.rb', line 17

def to_db
  send @comparator
end

#|(other) ⇒ Object



57
58
59
# File 'lib/perpetuity/mongodb/query_expression.rb', line 57

def | other
  QueryUnion.new(self, other)
end