Module: Persistence::Object::ObjectInstance
- Includes:
- CascadingConfiguration::Hash, CascadingConfiguration::Setting, ParsePersistenceArgs::ObjectInstance
- Defined in:
- lib/persistence/object/object_instance.rb
Overview
Instance methods for any objects enabled with persistence capabilities.
Instance Method Summary collapse
-
#block_indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index::BlockIndex}
Hash holding block indexes: index_name => index.
-
#cease! ⇒ Object
Remove object properties stored for object from persistence bucket and indexes.
-
#explicit_indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index::ExplicitIndex}
Hash holding explicit indexes: index_name => index.
-
#indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index}
Hash holding indexes: index_name => index.
-
#persist!(*args) ⇒ Object
Store object to persistence port.
-
#persisted? ⇒ true, false
Query whether object is persisted in port.
-
#persistence_bucket ⇒ Persistence::Port?
Get persistence bucket that will be used with this object.
-
#persistence_bucket=(persistence_bucket_class_or_name) ⇒ Object
Assign a persistence bucket to be used with this object.
-
#persistence_port ⇒ Persistence::Port?
Get persistence port that will be used with this object.
-
#persistence_port=(persistence_port_class_or_name) ⇒ Object
Assign a persistence port to be used with this object.
Methods included from ParsePersistenceArgs::ObjectInstance
#parse_object_args_for_index_value_no_value
Methods included from ParsePersistenceArgs
Instance Method Details
#block_indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index::BlockIndex}
Hash holding block indexes: index_name => index.
283 |
# File 'lib/persistence/object/object_instance.rb', line 283 attr_module_hash :block_indexes, ::Persistence::Object::IndexHash |
#cease! ⇒ Object
Remove object properties stored for object from persistence bucket and indexes.
243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/persistence/object/object_instance.rb', line 243 def cease! self.class.indexes.each do |this_index_name, this_index| this_index.delete_keys_for_object_id!( persistence_id ) end persistence_hash_from_port = persistence_bucket.delete_object!( persistence_id ) self.persistence_id = nil return persistence_hash_from_port end |
#explicit_indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index::ExplicitIndex}
Hash holding explicit indexes: index_name => index.
269 |
# File 'lib/persistence/object/object_instance.rb', line 269 attr_module_hash :explicit_indexes, ::Persistence::Object::IndexHash |
#indexes ⇒ CompositingHash{Symbol,String=>Persistence::Object::Index}
Hash holding indexes: index_name => index.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/persistence/object/object_instance.rb', line 297 attr_module_hash :indexes do #======================# # child_pre_set_hook # #======================# def child_pre_set_hook( index_name, index_instance ) child_instance = nil case index_instance when ::Persistence::Object::Index::ExplicitIndex child_instance = configuration_instance.explicit_indexes[ index_name ] when ::Persistence::Object::Index::BlockIndex child_instance = configuration_instance.block_indexes[ index_name ] when ::Persistence::Object::Complex::Index::AttributeIndex child_instance = configuration_instance.attribute_indexes[ index_name ] end return child_instance end end |
#persist! ⇒ Object #persist!(index_name, key) ⇒ Object #persist!(index_name_key_hash) ⇒ Object #persist!(index_instance, key) ⇒ Object #persist!(index_instance_key_hash) ⇒ Object
Store object to persistence port. Will cause all non-atomic properties to be updated if object has already
been persisted.
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 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/persistence/object/object_instance.rb', line 179 def persist!( *args ) index_instance, key, no_key = parse_object_args_for_index_value_no_value( args, false ) # call super to ensure object is persisted unless persistence_port raise ::Persistence::Exception::NoPortEnabled, 'No persistence port currently enabled.' end self.persistence_id = persistence_bucket.put_object!( self ) if index_instance # if we have an index make sure that we have a key if no_key raise ::Persistence::Exception::KeyValueRequired, 'Key required when specifying index for :persist!' end # and make sure we have an index that permits arbitrary keys unless self.class.explicit_indexes[ index_instance.name ] == index_instance raise ::Persistence::Exception::ExplicitIndexRequired, 'Index ' + index_instance.name.to_s + ' was not declared as an explicit index ' 'and thus does not permit arbitrary keys.' end index_instance.index_object( self, key ) end unless self.class.block_indexes.empty? self.class.block_indexes.each do |this_index_name, this_block_index| this_block_index.index_object( self ) end end return self end |
#persisted? ⇒ true, false
Query whether object is persisted in port.
228 229 230 231 232 233 234 |
# File 'lib/persistence/object/object_instance.rb', line 228 def persisted? bucket_name = persistence_port.get_bucket_name_for_object_id( persistence_id ) return bucket_name ? true : false end |
#persistence_bucket ⇒ Persistence::Port?
Get persistence bucket that will be used with this object. Will use name of class if bucket
does not already exist.
130 131 132 133 134 135 136 |
# File 'lib/persistence/object/object_instance.rb', line 130 def persistence_bucket # if specified at instance level, use specified value # otherwise, use value stored in class return super || self.class.instance_persistence_bucket end |
#instance_persistence_bucket=(bucket_name) ⇒ Object #instance_persistence_bucket=(bucket_instance) ⇒ Object
Assign a persistence bucket to be used with this object.
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 114 115 116 117 118 |
# File 'lib/persistence/object/object_instance.rb', line 86 def persistence_bucket=( persistence_bucket_class_or_name ) if persistence_bucket_class_or_name.nil? super( nil ) elsif persistence_bucket_class_or_name.is_a?( ::Persistence::Port::Bucket ) super( persistence_bucket_class_or_name ) elsif persistence_bucket_class_or_name.respond_to?( :instance_persistence_bucket ) # if arg responds to :instance_persistence_bucket we use arg's bucket super( persistence_bucket_class_or_name.instance_persistence_bucket ) elsif ! ( persistence_bucket_class_or_name.is_a?( String ) or persistence_bucket_class_or_name.is_a?( Symbol ) ) and persistence_bucket_class_or_name.respond_to?( :persistence_bucket ) # if arg responds to :persistence_bucket we use arg's bucket super( persistence_bucket_class_or_name.persistence_bucket ) else # otherwise we use arg as a symbol # this means classnames are ok (which are default) self.persistence_bucket = persistence_port.persistence_bucket( persistence_bucket_class_or_name.to_sym ) end return self end |
#persistence_port ⇒ Persistence::Port?
Get persistence port that will be used with this object. Will use instance persistence port if no port is assigned,
which will result in using the current port if no instance persistence port is specified.
60 61 62 63 64 65 66 |
# File 'lib/persistence/object/object_instance.rb', line 60 def persistence_port # if specified at instance level, use specified value # otherwise, use value stored in class return super || self.class.instance_persistence_port end |
#persistence_port=(port_name) ⇒ Object #persistence_port=(port_instance) ⇒ Object
Assign a persistence port to be used with this object.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/persistence/object/object_instance.rb', line 29 def persistence_port=( persistence_port_class_or_name ) case persistence_port_class_or_name when ::Symbol, ::String super( ::Persistence.port_for_name_or_port( persistence_port_class_or_name, true ) ) else if persistence_port_class_or_name.respond_to?( :persistence_port ) super( persistence_port_class_or_name.persistence_port ) end end return self end |