Class: Repository::Cursor
- Inherits:
-
Object
- Object
- Repository::Cursor
- Defined in:
- lib/repository/cursor.rb
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #eq(field, value) ⇒ Object
- #first ⇒ Object
- #gt(field, value) ⇒ Object
- #gte(field, value) ⇒ Object
- #in(field, value) ⇒ Object
-
#initialize(query_executor) ⇒ Cursor
constructor
A new instance of Cursor.
- #last ⇒ Object
- #like(field, value) ⇒ Object
- #limit(limit) ⇒ Object
- #lt(field, value) ⇒ Object
- #lte(field, value) ⇒ Object
- #not_eq(field, value) ⇒ Object
- #not_in(field, value) ⇒ Object
- #offset(offset) ⇒ Object
- #or(*filters) ⇒ Object
- #query ⇒ Object
- #remove! ⇒ Object
- #sort(field, order) ⇒ Object
Constructor Details
#initialize(query_executor) ⇒ Cursor
Returns a new instance of Cursor.
8 9 10 11 12 |
# File 'lib/repository/cursor.rb', line 8 def initialize(query_executor) @query_executor = query_executor @filters = [] @sorts = [] end |
Instance Method Details
#all ⇒ Object
91 92 93 |
# File 'lib/repository/cursor.rb', line 91 def all query_executor.execute_find(query) end |
#count ⇒ Object
87 88 89 |
# File 'lib/repository/cursor.rb', line 87 def count query_executor.execute_count(query) end |
#eq(field, value) ⇒ Object
14 15 16 17 |
# File 'lib/repository/cursor.rb', line 14 def eq(field, value) @filters << filter_factory.eq(field, value) self end |
#first ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/repository/cursor.rb', line 95 def first query_executor.execute_find( query.merge( sorts: sorts_for_first, limit: 1 )).first end |
#gt(field, value) ⇒ Object
34 35 36 37 |
# File 'lib/repository/cursor.rb', line 34 def gt(field, value) @filters << filter_factory.gt(field, value) self end |
#gte(field, value) ⇒ Object
39 40 41 42 |
# File 'lib/repository/cursor.rb', line 39 def gte(field, value) @filters << filter_factory.gte(field, value) self end |
#in(field, value) ⇒ Object
44 45 46 47 |
# File 'lib/repository/cursor.rb', line 44 def in(field, value) @filters << filter_factory.in(field, value) self end |
#last ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/repository/cursor.rb', line 103 def last query_executor.execute_find( query.merge( sorts: sorts_for_last, limit: 1 )).first end |
#like(field, value) ⇒ Object
54 55 56 57 |
# File 'lib/repository/cursor.rb', line 54 def like(field, value) @filters << filter_factory.like(field, value) self end |
#limit(limit) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/repository/cursor.rb', line 71 def limit(limit) if limit assert_int!('Limit', limit) @limit = limit.to_i end self end |
#lt(field, value) ⇒ Object
24 25 26 27 |
# File 'lib/repository/cursor.rb', line 24 def lt(field, value) @filters << filter_factory.lt(field, value) self end |
#lte(field, value) ⇒ Object
29 30 31 32 |
# File 'lib/repository/cursor.rb', line 29 def lte(field, value) @filters << filter_factory.lte(field, value) self end |
#not_eq(field, value) ⇒ Object
19 20 21 22 |
# File 'lib/repository/cursor.rb', line 19 def not_eq(field, value) @filters << filter_factory.not_eq(field, value) self end |
#not_in(field, value) ⇒ Object
49 50 51 52 |
# File 'lib/repository/cursor.rb', line 49 def not_in(field, value) @filters << filter_factory.not_in(field, value) self end |
#offset(offset) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/repository/cursor.rb', line 79 def offset(offset) if offset assert_int!('Offset', offset) @offset = offset.to_i end self end |
#or(*filters) ⇒ Object
59 60 61 62 |
# File 'lib/repository/cursor.rb', line 59 def or(*filters) @filters << filter_factory.or(*filters) self end |
#query ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/repository/cursor.rb', line 122 def query { :type => @type, :filters => @filters, :sorts => @sorts, :offset => @offset, :limit => @limit } end |
#remove! ⇒ Object
111 112 113 |
# File 'lib/repository/cursor.rb', line 111 def remove! query_executor.execute_remove!(query) end |