Module: Persistence::Adapter::Mock::Cursor::CursorInterface
- Included in:
- Persistence::Adapter::Mock::Cursor
- Defined in:
- lib/persistence/adapter/mock/cursor/cursor_interface.rb
Overview
Interface implementation for Mock adapter Cursor class instances.
Instance Method Summary collapse
-
#close ⇒ Object
Declare use of cursor complete.
-
#current ⇒ Object
Return the current object in cursor’s current context.
-
#current_key ⇒ Object
Return the current key in cursor’s current context.
-
#first ⇒ Object
Return the first object in cursor’s current context.
-
#first_key ⇒ Object
Return the first key in cursor’s current context.
- #initialize(bucket, index) ⇒ Object
-
#next ⇒ Object
Return the next object in cursor’s current context.
-
#next_key ⇒ Object
Return the next key in cursor’s current context.
-
#persisted?(key, ...) ⇒ true, false
Query whether keys are persisted in cursor’s current context.
-
#supports_bucket_order? ⇒ Boolean
supports_bucket_order? #.
-
#supports_index_order? ⇒ Boolean
supports_index_order? #.
Instance Method Details
#close ⇒ Object
Declare use of cursor complete.
55 56 57 58 59 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 55 def close # nothing required end |
#current ⇒ Object
Return the current object in cursor’s current context.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 167 def current # current should return the current ID or object hash current_id = nil if @current_item if @index current_id = @current_item[ 1 ] else current_id = @current_item[ 0 ] end end return current_id end |
#current_key ⇒ Object
Return the current key in cursor’s current context.
194 195 196 197 198 199 200 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 194 def current_key current_key = nil if @current_item current_key = @current_item[ 0 ] end return current_key end |
#first ⇒ Object
Return the first object in cursor’s current context.
Responsible for setting the cursor position.
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 125 def first # first should set the cursor position and return the first ID or object hash begin @current_item = @current_position.rewind.peek rescue StopIteration @current_item = nil end return current end |
#first_key ⇒ Object
Return the first key in cursor’s current context.
Responsible for setting the cursor position.
149 150 151 152 153 154 155 156 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 149 def first_key begin @current_item = @current_position.rewind.peek rescue StopIteration @current_item = nil end return current_key end |
#initialize(bucket, index) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 16 def initialize( bucket, index ) @persistence_bucket = bucket @index = index @id_source = index ? index.instance_variable_get( :@keys ) : bucket.instance_variable_get( :@objects ) @current_position = ( @id_source || { } ).each end |
#next ⇒ Object
Return the next object in cursor’s current context.
211 212 213 214 215 216 217 218 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 211 def next begin @current_item = @current_position.next rescue StopIteration @current_item = nil end return current end |
#next_key ⇒ Object
Return the next key in cursor’s current context.
229 230 231 232 233 234 235 236 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 229 def next_key begin @current_item = @current_position.next rescue StopIteration @current_item = nil end return current_key end |
#persisted?(key, ...) ⇒ true, false
Query whether keys are persisted in cursor’s current context.
Responsible for setting the cursor position.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 75 def persisted?( *args ) # persisted? is responsible for setting the cursor position key = nil # we expect 0 or 1 arg if args.count > 0 key = args[ 0 ] else # if we have no key we are asking if keys exist @current_position.rewind return @id_source.count > 0 ? true : false end has_key = false # rewind to beginning of bucket @current_position.rewind # iterate until we find our key begin while @current_item = @current_position.next if @current_item[ 0 ] == key has_key = true break end end rescue StopIteration @current_item = nil end return has_key end |
#supports_bucket_order? ⇒ Boolean
supports_bucket_order? #
32 33 34 35 36 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 32 def supports_bucket_order? return true end |
#supports_index_order? ⇒ Boolean
supports_index_order? #
42 43 44 45 46 |
# File 'lib/persistence/adapter/mock/cursor/cursor_interface.rb', line 42 def supports_index_order? return true end |