Class: Tyrion::Criteria
- Inherits:
-
Object
- Object
- Tyrion::Criteria
- Includes:
- Enumerable
- Defined in:
- lib/tyrion/criteria.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #all ⇒ Object
- #asc(*keys) ⇒ Object
- #desc(*keys) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(storage, klass) ⇒ Criteria
constructor
A new instance of Criteria.
- #inspect ⇒ Object
- #last ⇒ Object
- #limit(n) ⇒ Object
- #skip(n) ⇒ Object
- #where(params = {}) ⇒ Object
Constructor Details
#initialize(storage, klass) ⇒ Criteria
Returns a new instance of Criteria.
7 8 9 10 11 |
# File 'lib/tyrion/criteria.rb', line 7 def initialize(storage, klass) @storage = storage @klass = klass @constraints = [] end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/tyrion/criteria.rb', line 5 def klass @klass end |
Instance Method Details
#all ⇒ Object
13 14 15 |
# File 'lib/tyrion/criteria.rb', line 13 def all self end |
#asc(*keys) ⇒ Object
32 33 34 35 |
# File 'lib/tyrion/criteria.rb', line 32 def asc(*keys) @constraints << [:sort, [keys, true]] self end |
#desc(*keys) ⇒ Object
37 38 39 40 |
# File 'lib/tyrion/criteria.rb', line 37 def desc(*keys) @constraints << [:sort, [keys, false]] self end |
#each(&block) ⇒ Object
48 49 50 51 |
# File 'lib/tyrion/criteria.rb', line 48 def each(&block) fetch_documents if not @data @data.each{ |c| block.call(c) } end |
#inspect ⇒ Object
42 43 44 45 46 |
# File 'lib/tyrion/criteria.rb', line 42 def inspect "<Criteria:0x#{__id__.to_s(16)}\n" + " Model:#{@klass.capitalize},\n" + " Constraints: " + @constraints.inspect[1..-2] + ">" end |
#last ⇒ Object
53 54 55 |
# File 'lib/tyrion/criteria.rb', line 53 def last to_a.last end |
#limit(n) ⇒ Object
22 23 24 25 |
# File 'lib/tyrion/criteria.rb', line 22 def limit(n) @constraints << [:limit, n] self end |
#skip(n) ⇒ Object
27 28 29 30 |
# File 'lib/tyrion/criteria.rb', line 27 def skip(n) @constraints << [:skip, n] self end |
#where(params = {}) ⇒ Object
17 18 19 20 |
# File 'lib/tyrion/criteria.rb', line 17 def where(params = {}) @constraints << [:where, params] self end |