Class: Dynamoid::Criteria::Chain
- Inherits:
-
Object
- Object
- Dynamoid::Criteria::Chain
- Includes:
- Enumerable
- Defined in:
- lib/dynamoid/criteria/chain.rb
Overview
The criteria chain is equivalent to an ActiveRecord relation (and realistically I should change the name from chain to relation). It is a chainable object that builds up a query and eventually executes it either on an index or by a full table scan.
Instance Attribute Summary (collapse)
-
- (Object) query
Returns the value of attribute query.
-
- (Object) source
Returns the value of attribute source.
-
- (Object) values
Returns the value of attribute values.
Instance Method Summary (collapse)
-
- (Object) all
Returns all the records matching the criteria.
-
- (Object) each(&block)
Allows you to use the results of a search as an enumerable over the results found.
-
- (Object) first
Returns the first record matching the criteria.
-
- (Chain) initialize(source)
constructor
Create a new criteria chain.
-
- (Object) where(args)
The workhorse method of the criteria chain.
Constructor Details
- (Chain) initialize(source)
Create a new criteria chain.
15 16 17 18 |
# File 'lib/dynamoid/criteria/chain.rb', line 15 def initialize(source) @query = {} @source = source end |
Instance Attribute Details
- (Object) query
Returns the value of attribute query
9 10 11 |
# File 'lib/dynamoid/criteria/chain.rb', line 9 def query @query end |
- (Object) source
Returns the value of attribute source
9 10 11 |
# File 'lib/dynamoid/criteria/chain.rb', line 9 def source @source end |
- (Object) values
Returns the value of attribute values
9 10 11 |
# File 'lib/dynamoid/criteria/chain.rb', line 9 def values @values end |
Instance Method Details
- (Object) all
Returns all the records matching the criteria.
39 40 41 |
# File 'lib/dynamoid/criteria/chain.rb', line 39 def all records end |
- (Object) each(&block)
Allows you to use the results of a search as an enumerable over the results found.
53 54 55 |
# File 'lib/dynamoid/criteria/chain.rb', line 53 def each(&block) records.each(&block) end |
- (Object) first
Returns the first record matching the criteria.
46 47 48 |
# File 'lib/dynamoid/criteria/chain.rb', line 46 def first records.first end |
- (Object) where(args)
The workhorse method of the criteria chain. Each key in the passed in hash will become another criteria that the ultimate query must match. A key can either be a symbol or a string, and should be an attribute name or an attribute name with a range operator.
31 32 33 34 |
# File 'lib/dynamoid/criteria/chain.rb', line 31 def where(args) args.each {|k, v| query[k] = v} self end |