Module: Persistence::Adapter::FlatFile::Bucket::BucketInterface
- Includes:
- Abstract::PrimaryKey::Simple, PathHelpers, Serialization
- Included in:
- Persistence::Adapter::FlatFile::Bucket
- Defined in:
- lib/persistence/adapter/flat_file/bucket/bucket_interface.rb
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
-
#adapter_class ⇒ Object
adapter_class #.
-
#count ⇒ Object
count #.
-
#create_index(index_name, permits_duplicates) ⇒ Object
create_index #.
-
#cursor ⇒ Object
cursor #.
-
#delete_attribute!(global_id, attribute_name) ⇒ Object
delete_attribute! #.
-
#delete_index(index_name) ⇒ Object
delete_index #.
-
#delete_object!(global_id) ⇒ Object
delete_object! #.
-
#get_attribute(global_id, attribute_name) ⇒ Object
get_attribute #.
-
#get_object(global_id) ⇒ Object
get_object #.
-
#has_index?(index_name) ⇒ Boolean
has_index? #.
-
#index(index_name) ⇒ Object
index #.
-
#initialize(parent_adapter, bucket_name) ⇒ Object
initialize #.
-
#permits_duplicates?(index_name) ⇒ Boolean
permits_duplicates? #.
-
#put_attribute!(global_id, attribute_name, value) ⇒ Object
put_attribute! #.
-
#put_object!(object) ⇒ Object
must be recoverable by information in the object we currently use class and persistence key.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/persistence/adapter/flat_file/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/flat_file/bucket/bucket_interface.rb', line 9 def parent_adapter @parent_adapter end |
Instance Method Details
#adapter_class ⇒ Object
adapter_class #
29 30 31 32 33 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 29 def adapter_class return @parent_adapter.class end |
#count ⇒ Object
count #
49 50 51 52 53 54 55 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 49 def count glob_list = Dir.glob( File.join( directory__ids_in_bucket, '*' ) ) return glob_list.count end |
#create_index(index_name, permits_duplicates) ⇒ Object
create_index #
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 177 def create_index( index_name, permits_duplicates ) unless ( permits_duplicates_value = permits_duplicates?( index_name ) ).nil? if ! permits_duplicates_value != ! permits_duplicates raise 'Index on :' + index_name.to_s + ' already exists and ' + ( permits_duplicates ? 'does not permit' : 'permits' ) + ' duplicates, which conflicts.' end else file__permits_duplicates = file__index_permits_duplicates( index_name ) create_or_update_value_serialize_and_write( file__permits_duplicates, permits_duplicates ) end # create/instantiate the index index_instance = ::Persistence::Adapter::FlatFile::Bucket::Index.new( index_name, self, permits_duplicates ) # store index instance @indexes[ index_name ] = index_instance return index_instance end |
#cursor ⇒ Object
cursor #
39 40 41 42 43 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 39 def cursor return ::Persistence::Adapter::FlatFile::Cursor.new( self, nil ) end |
#delete_attribute!(global_id, attribute_name) ⇒ Object
delete_attribute! #
164 165 166 167 168 169 170 171 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 164 def delete_attribute!( global_id, attribute_name ) file__attribute = file__attributes( global_id, attribute_name ) # delete this attribute ::File.delete( file__attribute ) end |
#delete_index(index_name) ⇒ Object
delete_index #
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 243 def delete_index( index_name ) index_instance = @indexes.delete( index_name ) index_instance.delete # delete permits_duplicates File.delete( file__index_permits_duplicates( index_name ) ) return self end |
#delete_object!(global_id) ⇒ Object
delete_object! #
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 115 def delete_object!( global_id ) # delete flat properties ::Dir[ ::File.join( directory__attributes( global_id ), '*' ) ].each do |this_file| ::File.delete( this_file ) end file__ids_in_bucket = file__ids_in_bucket( global_id ) ::File.delete( file__ids_in_bucket ) @parent_adapter.delete_bucket_for_object_id( global_id ) @parent_adapter.delete_class_for_object_id( global_id ) return self end |
#get_attribute(global_id, attribute_name) ⇒ Object
get_attribute #
152 153 154 155 156 157 158 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 152 def get_attribute( global_id, attribute_name ) file__attribute = file__attributes( global_id, attribute_name ) return open_read_unserialize_and_close( file__attribute ) end |
#get_object(global_id) ⇒ Object
get_object #
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 91 def get_object( global_id ) persistence_hash_from_port = { } # iterate directory of flat objects and unload into hash ::Dir[ ::File.join( directory__attributes( global_id ), '*' ) ].each do |this_file| # unserialize contents of file at path for flat attribute value this_attribute = attribute_name_from_file_path( this_file ) this_attribute = this_attribute.to_sym if this_attribute this_value = open_read_unserialize_and_close( this_file ) persistence_hash_from_port[ this_attribute ] = this_value end return persistence_hash_from_port.empty? ? nil : persistence_hash_from_port end |
#has_index?(index_name) ⇒ Boolean
has_index? #
221 222 223 224 225 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 221 def has_index?( index_name ) return @indexes.has_key?( index_name ) end |
#index(index_name) ⇒ Object
index #
211 212 213 214 215 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 211 def index( index_name ) return @indexes[ index_name ] end |
#initialize(parent_adapter, bucket_name) ⇒ Object
initialize #
15 16 17 18 19 20 21 22 23 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 15 def initialize( parent_adapter, bucket_name ) @parent_adapter = parent_adapter @name = bucket_name # storage for index objects @indexes = { } end |
#permits_duplicates?(index_name) ⇒ Boolean
permits_duplicates? #
231 232 233 234 235 236 237 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 231 def permits_duplicates?( index_name ) file__permits_duplicates = file__index_permits_duplicates( index_name ) return open_read_unserialize_and_close( file__permits_duplicates ) end |
#put_attribute!(global_id, attribute_name, value) ⇒ Object
put_attribute! #
138 139 140 141 142 143 144 145 146 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 138 def put_attribute!( global_id, attribute_name, value ) file__attribute = file__attributes( global_id, attribute_name ) create_or_update_value_serialize_and_write( file__attribute, value ) return self end |
#put_object!(object) ⇒ Object
must be recoverable by information in the object we currently use class and persistence key
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/persistence/adapter/flat_file/bucket/bucket_interface.rb', line 63 def put_object!( object ) @parent_adapter.ensure_object_has_globally_unique_id( object ) # write ID to bucket's contents file__ids_in_bucket = file__ids_in_bucket( object.persistence_id ) create_or_update_value_serialize_and_write( file__ids_in_bucket, object.persistence_id ) object_persistence_hash = object.persistence_hash_to_port # iterate flat properties: # * remove delete cascades for this attribute object_persistence_hash.each do |this_attribute, this_attribute_value| file__attribute = file__attributes( object.persistence_id, this_attribute ) create_or_update_value_serialize_and_write( file__attribute, this_attribute_value ) end return object.persistence_id end |