Module: Persistence::Port::Bucket::BucketInterface
- Includes:
- Enumerable, Object::Flat::File::FilePersistence
- Included in:
- Persistence::Port::Bucket
- Defined in:
- lib/persistence/port/bucket/bucket_interface.rb
Overview
Interface for Bucket implementation. Provided separately for easy overriding.
Instance Attribute Summary collapse
-
#name ⇒ Symbol, String
Name.
-
#Name of bucket(ofbucket) ⇒ Symbol, String
readonly
Name.
-
#parent_port ⇒ Object
parent_port #.
Instance Method Summary collapse
-
#adapter_bucket ⇒ Object
Retrieve parallel adapter bucket instance.
-
#atomic_cursor(*args) ⇒ Persistence::Cursor
Create and return cursor instance for this index enabled to load all object properties as atomic.
-
#count(*args, &count_block) ⇒ Integer
Get the number of objects in index.
-
#create_index(index_name, sort_by_proc = nil, &indexing_block) ⇒ Object
Create a bucket index, which is a block index that runs on each inserted object, regardless of type.
-
#create_index_with_duplicates(index_name, sort_by_proc = nil, sort_duplicates_by_proc = nil, &indexing_block) ⇒ Object
Create a bucket index that permits duplicates.
-
#cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this bucket.
-
#delete_attribute!(object, attribute_name) ⇒ Object
Delete attribute for object from port.
-
#delete_index_for_object(object, index_name) ⇒ Object
Delete indexed entries for object.
-
#delete_index_for_object_id(global_id, index_name) ⇒ Object
Delete indexed entries for object.
-
#delete_object!(global_id) ⇒ Hash
Delete object from persistence port.
-
#disable ⇒ Object
Disable bucket when port disables.
-
#each {|object| ... } ⇒ Object
Iterate objects in current bucket.
-
#get_attribute(object, attribute_name) ⇒ Object
Get attribute for object from port.
-
#get_flat_object(global_id) ⇒ Object
Get flat object from persistence port.
-
#get_object(global_id) ⇒ Object
Get object from persistence port.
-
#get_object_hash(global_id) ⇒ Hash
Get object properties from persistence port.
-
#has_attribute_index?(index_name, ...) ⇒ true, false
Query whether attribute index(es) exist for object.
-
#index(index_name, ensure_exists = false) ⇒ Persistence::Object::Index
Retrieve index.
- #initialize(parent_port, bucket_name) ⇒ Object
-
#initialize_for_port(port) ⇒ Object
Initialize bucket for a port that has been enabled.
-
#pend_index(index_instance) ⇒ Object
Pend index instance for port to be enabled.
-
#persists_file_paths_as_strings? ⇒ Boolean
persists_file_paths_as_strings? #.
-
#persists_files_by_content? ⇒ Boolean
persists_files_by_content? #.
-
#persists_files_by_path? ⇒ Boolean
persists_files_by_path? #.
-
#primary_key_for_attribute_name(object, attribute_name) ⇒ String
Generate primary key for storage for attribute name on object.
-
#put_attribute!(object, attribute_name, attribute_value) ⇒ Object
Put attribute for object to port.
-
#put_object!(object) ⇒ Object
Put object properties to persistence port.
Methods included from Object::Flat::File::FilePersistence
#persist_files_by_content!, #persist_files_by_path!
Instance Attribute Details
#name ⇒ Symbol, String
Returns Name.
98 99 100 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 98 def name @name end |
#Name of bucket(ofbucket) ⇒ Symbol, String (readonly)
Returns Name.
98 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 98 attr_accessor :name |
#parent_port ⇒ Object
parent_port #
104 105 106 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 104 def parent_port @parent_port end |
Instance Method Details
#adapter_bucket ⇒ Object
Retrieve parallel adapter bucket instance.
79 80 81 82 83 84 85 86 87 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 79 def adapter_bucket unless @adapter_bucket raise 'Persistence port must be enabled first.' end return @adapter_bucket end |
#atomic_cursor(*args) ⇒ Persistence::Cursor
Create and return cursor instance for this index enabled to load all object properties as atomic.
See Persistence::Cursor#atomize.
593 594 595 596 597 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 593 def atomic_cursor( *args ) return cursor( *args ).atomize end |
#count(*args, &count_block) ⇒ Integer
Get the number of objects in index. See Enumerable.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 231 def count( *args, & count_block ) return_value = 0 if block_given? return_value = super( & count_block ) elsif args.empty? return_value = adapter_bucket.count else return_value = super( *args ) end return return_value end |
#create_index(index_name, sort_by_proc = nil, &indexing_block) ⇒ Object
Create a bucket index, which is a block index that runs on each inserted object, regardless of type.
134 135 136 137 138 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 134 def create_index( index_name, sort_by_proc = nil, & indexing_block ) return create_bucket_index( index_name, false, sort_by_proc, & indexing_block ) end |
#create_index_with_duplicates(index_name, sort_by_proc = nil, sort_duplicates_by_proc = nil, &indexing_block) ⇒ Object
Create a bucket index that permits duplicates.
147 148 149 150 151 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 147 def create_index_with_duplicates( index_name, sort_by_proc = nil, sort_duplicates_by_proc = nil, & indexing_block ) return create_bucket_index( index_name, true, sort_by_proc, sort_duplicates_by_proc, & indexing_block ) end |
#cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this bucket.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 566 def cursor( *args, & block ) cursor_instance = ::Persistence::Cursor.new( self ) if args.count > 0 cursor_instance.persisted?( *args ) end if block_given? cursor_instance = cursor_instance.instance_eval( & block ) cursor_instance.close end return cursor_instance end |
#delete_attribute!(object, attribute_name) ⇒ Object
Delete attribute for object from port.
474 475 476 477 478 479 480 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 474 def delete_attribute!( object, attribute_name ) primary_key = primary_key_for_attribute_name( object, attribute_name ) return adapter_bucket.delete_attribute!( object, primary_key ) end |
#delete_index_for_object(object, index_name) ⇒ Object
Delete indexed entries for object.
260 261 262 263 264 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 260 def delete_index_for_object( object, index_name ) return delete_index_for_object_id( object.persistence_id ) end |
#delete_index_for_object_id(global_id, index_name) ⇒ Object
Delete indexed entries for object.
279 280 281 282 283 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 279 def delete_index_for_object_id( global_id, index_name ) return adapter_bucket.delete_index_for_object_id( global_id ) end |
#delete_object!(global_id) ⇒ Hash
Delete object from persistence port.
455 456 457 458 459 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 455 def delete_object!( global_id ) return adapter_bucket.delete_object!( global_id ) end |
#disable ⇒ Object
Disable bucket when port disables. Internal helper method necessary to ensure that old references don’t stick around.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 116 def disable @adapter_bucket = nil @parent_port = nil @indexes.each do |this_index_name, this_index| this_index.disable end end |
#each {|object| ... } ⇒ Object
Iterate objects in current bucket.
610 611 612 613 614 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 610 def each( & block ) return atomic_cursor.each( & block ) end |
#get_attribute(object, attribute_name) ⇒ Object
Get attribute for object from port.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 298 def get_attribute( object, attribute_name ) primary_key = primary_key_for_attribute_name( object, attribute_name ) attribute_value = adapter_bucket.get_attribute( object, primary_key ) if attribute_value.is_a?( ::Persistence::Object::Complex::ComplexObject ) attribute_value.persistence_port = object.persistence_port attribute_value = attribute_value.persist end return attribute_value end |
#get_flat_object(global_id) ⇒ Object
Get flat object from persistence port.
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 426 def get_flat_object( global_id ) flat_object = nil if persistence_value_hash = adapter_bucket.get_object( global_id ) if persistence_value_key_data = persistence_value_hash.first flat_object = persistence_value_key_data[ 1 ] flat_object.persistence_id = global_id end end return flat_object end |
#get_object(global_id) ⇒ Object
Get object from persistence port.
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 366 def get_object( global_id ) object = nil # get the class if klass = @parent_port.get_class_for_object_id( global_id ) object = klass.new object.persistence_id = global_id # if we have non-atomic attributes, load them unless klass.non_atomic_attribute_readers.empty? if persistence_hash_from_port = get_object_hash( global_id ) object.load_persistence_hash( object.persistence_port, persistence_hash_from_port ) end end end return object end |
#get_object_hash(global_id) ⇒ Hash
Get object properties from persistence port.
407 408 409 410 411 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 407 def get_object_hash( global_id ) return adapter_bucket.get_object( global_id ) end |
#has_attribute_index?(index_name, ...) ⇒ true, false
Query whether attribute index(es) exist for object.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 210 def has_index?( *indexes ) has_index = false indexes.each do |this_index| break unless has_index = @indexes.has_key?( index_name ) end return has_index end |
#index(index_name, ensure_exists = false) ⇒ Persistence::Object::Index
Retrieve index.
183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 183 def index( index_name, ensure_exists = false ) index_instance = nil unless index_instance = @indexes[ index_name ] if ensure_exists raise ::ArgumentError, 'No index found by name ' << index_name.to_s + '.' end end return index_instance end |
#initialize(parent_port, bucket_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 21 def initialize( parent_port, bucket_name ) @name = bucket_name @indexes = { } @pending_indexes = [ ] if parent_port initialize_for_port( parent_port ) end end |
#initialize_for_port(port) ⇒ Object
Initialize bucket for a port that has been enabled.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 43 def initialize_for_port( port ) if port = ::Persistence.port_for_name_or_port( port ) and port.enabled? @parent_port = ::Persistence.port_for_name_or_port( port ) if @parent_port.enabled? @adapter_bucket = @parent_port.adapter.persistence_bucket( @name ) end @indexes.each do |this_index_name, this_index_instance| this_index_instance.initialize_for_bucket( self ) end @pending_indexes.delete_if do |this_pending_index| this_pending_index.initialize_for_bucket( self ) true end else disable end end |
#pend_index(index_instance) ⇒ Object
Pend index instance for port to be enabled.
164 165 166 167 168 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 164 def pend_index( index_instance ) @pending_indexes.push( index_instance ) end |
#persists_file_paths_as_strings? ⇒ Boolean
persists_file_paths_as_strings? #
543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 543 def persists_file_paths_as_strings? persists_file_paths_as_strings = nil persists_file_paths_as_strings = super if persists_file_paths_as_strings.nil? persists_file_paths_as_strings = parent_port.persists_file_paths_as_strings? end return persists_file_paths_as_strings end |
#persists_files_by_content? ⇒ Boolean
persists_files_by_content? #
507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 507 def persists_files_by_content? persists_files_by_content = nil persists_files_by_content = super if persists_files_by_content.nil? persists_files_by_content = parent_port.persists_files_by_content? end return persists_files_by_content end |
#persists_files_by_path? ⇒ Boolean
persists_files_by_path? #
525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 525 def persists_files_by_path? persists_files_by_path = nil persists_files_by_path = super if persists_files_by_path.nil? persists_files_by_path = parent_port.persists_files_by_path? end return persists_files_by_path end |
#primary_key_for_attribute_name(object, attribute_name) ⇒ String
Generate primary key for storage for attribute name on object.
497 498 499 500 501 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 497 def primary_key_for_attribute_name( object, attribute_name ) return adapter_bucket.primary_key_for_attribute_name( object, attribute_name ) end |
#put_attribute!(object, attribute_name, attribute_value) ⇒ Object
Put attribute for object to port.
328 329 330 331 332 333 334 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 328 def put_attribute!( object, attribute_name, attribute_value ) primary_key = primary_key_for_attribute_name( object, attribute_name ) return adapter_bucket.put_attribute!( object, primary_key, attribute_value ) end |
#put_object!(object) ⇒ Object
Put object properties to persistence port.
347 348 349 350 351 |
# File 'lib/persistence/port/bucket/bucket_interface.rb', line 347 def put_object!( object ) return adapter_bucket.put_object!( object ) end |