Class: Perpetuity::MongoDB::QueryExpression
- Inherits:
-
Object
- Object
- Perpetuity::MongoDB::QueryExpression
- Defined in:
- lib/perpetuity/mongodb/query_expression.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#comparator ⇒ Object
Returns the value of attribute comparator.
-
#negated ⇒ Object
Returns the value of attribute negated.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #&(other) ⇒ Object
- #==(other) ⇒ Object
- #equals ⇒ Object
- #function(func) ⇒ Object
- #greater_than ⇒ Object
- #gte ⇒ Object
- #in ⇒ Object
-
#initialize(attribute, comparator, value) ⇒ QueryExpression
constructor
A new instance of QueryExpression.
- #less_than ⇒ Object
- #lte ⇒ Object
- #matches ⇒ Object
- #negate ⇒ Object
- #not_equal ⇒ Object
- #to_db ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(attribute, comparator, value) ⇒ QueryExpression
Returns a new instance of QueryExpression.
9 10 11 12 13 14 15 16 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 9 def initialize attribute, comparator, value @attribute = attribute @comparator = comparator @value = value @negated = false @attribute = @attribute.to_sym if @attribute.respond_to? :to_sym end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
7 8 9 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 7 def attribute @attribute end |
#comparator ⇒ Object
Returns the value of attribute comparator.
7 8 9 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 7 def comparator @comparator end |
#negated ⇒ Object
Returns the value of attribute negated.
7 8 9 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 7 def negated @negated end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 7 def value @value end |
Instance Method Details
#&(other) ⇒ Object
76 77 78 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 76 def & other QueryIntersection.new(self, other) end |
#==(other) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 86 def == other attribute == other.attribute && comparator == other.comparator && value == other.value && negated == other.negated end |
#equals ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 22 def equals if @negated { @attribute => { '$ne' => @value } } else { @attribute => @value } end end |
#function(func) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 30 def function func f = { func => @value } if @negated { @attribute => { '$not' => f } } else { @attribute => f } end end |
#greater_than ⇒ Object
48 49 50 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 48 def greater_than function '$gt' end |
#gte ⇒ Object
52 53 54 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 52 def gte function '$gte' end |
#in ⇒ Object
60 61 62 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 60 def in function '$in' end |
#less_than ⇒ Object
40 41 42 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 40 def less_than function '$lt' end |
#lte ⇒ Object
44 45 46 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 44 def lte function '$lte' end |
#matches ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 64 def matches if @negated { @attribute => { '$not' => @value } } else { @attribute => @value } end end |
#negate ⇒ Object
80 81 82 83 84 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 80 def negate expr = dup expr.negated = true expr end |
#not_equal ⇒ Object
56 57 58 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 56 def not_equal function '$ne' end |
#to_db ⇒ Object
18 19 20 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 18 def to_db public_send @comparator end |
#|(other) ⇒ Object
72 73 74 |
# File 'lib/perpetuity/mongodb/query_expression.rb', line 72 def | other QueryUnion.new(self, other) end |