Class: RDBI::Driver::Mock::Cursor

Inherits:
Cursor
  • Object
show all
Defined in:
lib/rdbi/driver/mock.rb

Instance Method Summary collapse

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_countObject



97
98
99
# File 'lib/rdbi/driver/mock.rb', line 97

def affected_count
  16 # magic number
end

#allObject



114
115
116
# File 'lib/rdbi/driver/mock.rb', line 114

def all
  @handle.dup
end

#empty?Boolean

Returns:

  • (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

#firstObject



101
102
103
# File 'lib/rdbi/driver/mock.rb', line 101

def first
  @handle.first
end

#lastObject



105
106
107
# File 'lib/rdbi/driver/mock.rb', line 105

def last
  @handle.last
end

#last_row?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/rdbi/driver/mock.rb', line 122

def last_row?
  @index == @handle.size
end

#next_rowObject



87
88
89
90
91
# File 'lib/rdbi/driver/mock.rb', line 87

def next_row
  retval = @handle[@index]
  @index += 1
  return retval
end

#restObject



109
110
111
112
# File 'lib/rdbi/driver/mock.rb', line 109

def rest
  oindex, @index = @index, @handle.size
  @handle[oindex, @index]
end

#result_countObject



93
94
95
# File 'lib/rdbi/driver/mock.rb', line 93

def result_count
  @handle.size
end

#rewindObject

Raises:

  • (StandardError)


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