Class: RDBI::Driver::Mock::Cursor
- Inherits:
-
Cursor
- Object
- Cursor
- RDBI::Driver::Mock::Cursor
- Defined in:
- lib/rdbi/driver/mock.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #affected_count ⇒ Object
- #all ⇒ Object
- #empty? ⇒ Boolean
- #fetch(count = 1) ⇒ Object
- #first ⇒ Object
-
#initialize(handle) ⇒ Cursor
constructor
A new instance of Cursor.
- #last ⇒ Object
- #last_row? ⇒ Boolean
- #next_row ⇒ Object
- #rest ⇒ Object
- #result_count ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(handle) ⇒ Cursor
Returns a new instance of Cursor.
75 76 77 78 |
# File 'lib/rdbi/driver/mock.rb', line 75 def initialize(handle) super(handle.dup) @index = 0 end |
Instance Method Details
#[](index) ⇒ Object
118 119 120 |
# File 'lib/rdbi/driver/mock.rb', line 118 def [](index) @handle[index] end |
#affected_count ⇒ Object
97 98 99 |
# File 'lib/rdbi/driver/mock.rb', line 97 def affected_count 16 # magic number end |
#all ⇒ Object
114 115 116 |
# File 'lib/rdbi/driver/mock.rb', line 114 def all @handle.dup end |
#empty? ⇒ Boolean
131 132 133 |
# File 'lib/rdbi/driver/mock.rb', line 131 def empty? @handle.empty? end |
#fetch(count = 1) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/rdbi/driver/mock.rb', line 80 def fetch(count=1) return [] if last_row? a = [] count.times { a.push(next_row) } return a end |
#first ⇒ Object
101 102 103 |
# File 'lib/rdbi/driver/mock.rb', line 101 def first @handle.first end |
#last ⇒ Object
105 106 107 |
# File 'lib/rdbi/driver/mock.rb', line 105 def last @handle.last end |
#last_row? ⇒ Boolean
122 123 124 |
# File 'lib/rdbi/driver/mock.rb', line 122 def last_row? @index == @handle.size end |
#next_row ⇒ Object
87 88 89 90 91 |
# File 'lib/rdbi/driver/mock.rb', line 87 def next_row retval = @handle[@index] @index += 1 return retval end |
#rest ⇒ Object
109 110 111 112 |
# File 'lib/rdbi/driver/mock.rb', line 109 def rest oindex, @index = @index, @handle.size @handle[oindex, @index] end |
#result_count ⇒ Object
93 94 95 |
# File 'lib/rdbi/driver/mock.rb', line 93 def result_count @handle.size end |
#rewind ⇒ Object
126 127 128 129 |
# File 'lib/rdbi/driver/mock.rb', line 126 def rewind raise StandardError, "cannot rewind without rewindable_result set to true" unless rewindable_result @index = 0 end |