Module: Humanoid::Criterion::Inclusion
- Included in:
- Humanoid::Criteria
- Defined in:
- lib/humanoid/criterion/inclusion.rb
Instance Method Summary collapse
-
#all(attributes = {}) ⇒ Object
Adds a criterion to the
Criteria
that specifies values that must all be matched in order to return results. -
#and(selector = nil) ⇒ Object
Adds a criterion to the
Criteria
that specifies values that must be matched in order to return results. -
#in(attributes = {}) ⇒ Object
Adds a criterion to the
Criteria
that specifies values where any can be matched in order to return results. -
#where(selector = nil) ⇒ Object
Adds a criterion to the
Criteria
that specifies values that must be matched in order to return results.
Instance Method Details
#all(attributes = {}) ⇒ Object
Adds a criterion to the Criteria
that specifies values that must all be matched in order to return results. Similar to an “in” clause but the underlying conditional logic is an “AND” and not an “OR”. The MongoDB conditional operator that will be used is “$all”.
Options:
attributes: A Hash
where the key is the field name and the value is an Array
of values that must all match.
Example:
criteria.all(:field => ["value1", "value2"])
criteria.all(:field1 => ["value1", "value2"], :field2 => ["value1"])
Returns: self
22 23 24 |
# File 'lib/humanoid/criterion/inclusion.rb', line 22 def all(attributes = {}) update_selector(attributes, "$all") end |
#and(selector = nil) ⇒ Object
Adds a criterion to the Criteria
that specifies values that must be matched in order to return results. This is similar to a SQL “WHERE” clause. This is the actual selector that will be provided to MongoDB, similar to the Javascript object that is used when performing a find() in the MongoDB console.
Options:
selectior: A Hash
that must match the attributes of the Document
.
Example:
criteria.and(:field1 => "value1", :field2 => 15)
Returns: self
41 42 43 |
# File 'lib/humanoid/criterion/inclusion.rb', line 41 def and(selector = nil) where(selector) end |
#in(attributes = {}) ⇒ Object
Adds a criterion to the Criteria
that specifies values where any can be matched in order to return results. This is similar to an SQL “IN” clause. The MongoDB conditional operator that will be used is “$in”.
Options:
attributes: A Hash
where the key is the field name and the value is an Array
of values that any can match.
Example:
criteria.in(:field => ["value1", "value2"])
criteria.in(:field1 => ["value1", "value2"], :field2 => ["value1"])
Returns: self
61 62 63 |
# File 'lib/humanoid/criterion/inclusion.rb', line 61 def in(attributes = {}) update_selector(attributes, "$in") end |
#where(selector = nil) ⇒ Object
Adds a criterion to the Criteria
that specifies values that must be matched in order to return results. This is similar to a SQL “WHERE” clause. This is the actual selector that will be provided to MongoDB, similar to the Javascript object that is used when performing a find() in the MongoDB console.
Options:
selectior: A Hash
that must match the attributes of the Document
.
Example:
criteria.where(:field1 => "value1", :field2 => 15)
Returns: self
80 81 82 83 84 85 86 87 88 |
# File 'lib/humanoid/criterion/inclusion.rb', line 80 def where(selector = nil) case selector when String @selector.update("$where" => selector) else @selector.update(selector ? selector. : {}) end self end |