Module: Persistence::Adapter::Mock::Bucket::BucketInterface
- Includes:
- Abstract::PrimaryKey::Simple
- Included in:
- Persistence::Adapter::Mock::Bucket
- Defined in:
- lib/persistence/adapter/mock/bucket/bucket_interface.rb
Overview
Interface implementation for Bucket class instances.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent_adapter ⇒ Object
Returns the value of attribute parent_adapter.
Instance Method Summary collapse
-
#count ⇒ Integer
Get the number of objects in this bucket.
-
#create_index(index_name, permits_duplicates) ⇒ Persistence::Adapter::Mock::Bucket::Index
Create and return index for this bucket.
-
#cursor ⇒ Persistence::Adapter::Mock::Cursor
Create and return cursor instance for this bucket.
-
#delete_attribute!(object, attribute_name) ⇒ Object
Delete object property stored in this bucket.
-
#delete_index(index_name) ⇒ Persistence::Adapter::Mock::Bucket::Index
Delete index for this bucket.
-
#delete_object!(global_id) ⇒ Hash{Symbol,String=>Object}
Delete object properties from this bucket.
-
#get_attribute(object, attribute_name) ⇒ Object
Get object property stored in this bucket.
-
#get_object(global_id) ⇒ Integer
Retrieve object properties from this bucket.
-
#has_index?(index_name) ⇒ true, false
Reports whether bucket has index by name.
-
#index(index_name) ⇒ Persistence::Adapter::Mock::Bucket::Index
Get index for this bucket.
- #initialize(name) ⇒ Object
-
#put_attribute!(object, attribute_name, attribute_value) ⇒ Object
Store object property in this bucket.
-
#put_object!(object) ⇒ Integer
Store object properties in this bucket.
Methods included from Abstract::PrimaryKey::Simple
#primary_key_for_attribute_name
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 9 def name @name end |
#parent_adapter ⇒ Object
Returns the value of attribute parent_adapter.
9 10 11 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 9 def parent_adapter @parent_adapter end |
Instance Method Details
#count ⇒ Integer
Get the number of objects in this bucket.
39 40 41 42 43 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 39 def count return @objects.count end |
#create_index(index_name, permits_duplicates) ⇒ Persistence::Adapter::Mock::Bucket::Index
Create and return index for this bucket.
200 201 202 203 204 205 206 207 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 200 def create_index( index_name, permits_duplicates ) index_instance = ::Persistence::Adapter::Mock::Bucket::Index.new( index_name, self, permits_duplicates ) @indexes[ index_name ] = index_instance return index_instance end |
#cursor ⇒ Persistence::Adapter::Mock::Cursor
Create and return cursor instance for this bucket.
182 183 184 185 186 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 182 def cursor return ::Persistence::Adapter::Mock::Cursor.new( self, nil ) end |
#delete_attribute!(object, attribute_name) ⇒ Object
Delete object property stored in this bucket.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 161 def delete_attribute!( object, attribute_name ) deleted_value = nil if @objects[ object.persistence_id ] deleted_value = @objects[ object.persistence_id ].delete( attribute_name ) end return deleted_value end |
#delete_index(index_name) ⇒ Persistence::Adapter::Mock::Bucket::Index
Delete index for this bucket.
237 238 239 240 241 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 237 def delete_index( index_name ) return @indexes.delete( index_name ) end |
#delete_object!(global_id) ⇒ Hash{Symbol,String=>Object}
Delete object properties from this bucket.
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 94 def delete_object!( global_id ) persistence_hash_in_port = @objects[ global_id ] # and now delete the object's ID reference @objects.delete( global_id ) parent_adapter.delete_bucket_for_object_id( global_id ) parent_adapter.delete_class_for_object_id( global_id ) return persistence_hash_in_port end |
#get_attribute(object, attribute_name) ⇒ Object
Get object property stored in this bucket.
141 142 143 144 145 146 147 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 141 def get_attribute( object, attribute_name ) @objects[ object.persistence_id ] ||= { } return @objects[ object.persistence_id ][ attribute_name ] end |
#get_object(global_id) ⇒ Integer
Retrieve object properties from this bucket.
77 78 79 80 81 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 77 def get_object( global_id ) return @objects[ global_id ] end |
#has_index?(index_name) ⇒ true, false
Reports whether bucket has index by name.
254 255 256 257 258 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 254 def has_index?( index_name ) return @indexes.has_key?( index_name ) end |
#index(index_name) ⇒ Persistence::Adapter::Mock::Bucket::Index
Get index for this bucket.
220 221 222 223 224 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 220 def index( index_name ) return @indexes[ index_name ] end |
#initialize(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 19 def initialize( name ) super() if defined?( super ) @name = name @objects = { } @indexes = { } end |
#put_attribute!(object, attribute_name, attribute_value) ⇒ Object
Store object property in this bucket.
120 121 122 123 124 125 126 127 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 120 def put_attribute!( object, attribute_name, attribute_value ) @objects[ object.persistence_id ] ||= { } @objects[ object.persistence_id ][ attribute_name ] = ( attribute_name.is_a?( Symbol ) ? attribute_value : attribute_value.dup ) return self end |
#put_object!(object) ⇒ Integer
Store object properties in this bucket.
56 57 58 59 60 61 62 63 64 |
# File 'lib/persistence/adapter/mock/bucket/bucket_interface.rb', line 56 def put_object!( object ) parent_adapter.ensure_object_has_globally_unique_id( object ) object_persistence_hash = object.persistence_hash_to_port @objects[ object.persistence_id ] = object_persistence_hash return object.persistence_id end |