Module: Persistence::Object::Index
- Includes:
- CascadingConfiguration::Setting, Enumerable
- Included in:
- Complex::Index::AttributeIndex::AttributeIndexInterface, BlockIndex::BlockIndexInterface, ExplicitIndex::ExplicitIndexInterface
- Defined in:
- lib/persistence/object/index.rb,
lib/namespaces.rb
Overview
Common module to all index instances that serves as base index type.
Defined Under Namespace
Classes: BlockIndex, ExplicitIndex
Instance Attribute Summary collapse
-
#parent_bucket ⇒ Persistence::Port::Bucket
readonly
Get reference to bucket index indexes.
Instance Method Summary collapse
-
#adapter_index ⇒ Object
Get adapter index (provided by adapter) associated with bucket index (provided by Persistence::Object::Index).
-
#atomic_cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this index enabled to load all object properties as atomic.
-
#count(*args, &block) ⇒ Integer
Get the number of objects in index.
-
#cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this index.
-
#delete_keys_for_object!(object) ⇒ Object
Delete keys associated with object instance.
-
#delete_keys_for_object_id!(global_id) ⇒ Object
Delete keys associated with object persistence ID.
-
#disable ⇒ Object
Disable bucket.
-
#each {|object| ... } ⇒ Object
Iterate objects in current bucket.
-
#get_object_id(key) ⇒ Object
Get object ID for key in index.
-
#index_existing_objects ⇒ Object
(also: #sync_index)
Index objects that currently exist in parent bucket.
-
#index_object(object, key) ⇒ Object
Index key for object instance.
-
#index_object_id(global_id, key) ⇒ Object
Index key for object persistence ID.
-
#init_sorting_procs(sorting_proc_or_sort_name, duplicates_sorting_proc_or_sort_name) ⇒ Object
Initializes sorting procs from procs or sorting method names.
- #initialize(index_name, parent_bucket, permits_duplicates = nil, sorting_proc_or_sort_names = nil, duplicates_sorting_proc_or_sort_names = nil, ancestor_index_instance = nil) ⇒ Object
-
#initialize_for_bucket(parent_bucket) ⇒ Object
Initialize for parent bucket.
-
#name ⇒ Symbol, String
Index name.
-
#permits_duplicates? ⇒ true, false
Query whether index permits duplicates.
-
#persisted?(key) ⇒ true, false
Query whether key exists in index.
-
#sorting_proc_for_sort_name(sort_name) ⇒ Proc
Get sorting proc associated with sorting method name.
Instance Attribute Details
#parent_bucket ⇒ Persistence::Port::Bucket (readonly)
Get reference to bucket index indexes.
89 90 91 |
# File 'lib/persistence/object/index.rb', line 89 def parent_bucket @parent_bucket end |
Instance Method Details
#adapter_index ⇒ Object
Get adapter index (provided by adapter) associated with bucket index (provided by
{Persistence::Object::Index Persistence::Object::Index}).
348 349 350 351 352 353 354 355 356 |
# File 'lib/persistence/object/index.rb', line 348 def adapter_index unless @adapter_index raise 'Persistence port must be enabled first.' end return @adapter_index end |
#atomic_cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this index enabled to load all object properties as atomic.
See Persistence::Cursor#atomize.
297 298 299 300 301 |
# File 'lib/persistence/object/index.rb', line 297 def atomic_cursor( *args, & block ) return cursor( *args, & block ).atomize end |
#count(*args, &block) ⇒ Integer
Get the number of objects in index. See Enumerable.
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/persistence/object/index.rb', line 367 def count( *args, & block ) return_value = 0 if block_given? return_value = super( & block ) elsif args.empty? return_value = adapter_index.count else return_value = super( *args ) end return return_value end |
#cursor(*args, &block) ⇒ Persistence::Cursor
Create and return cursor instance for this index.
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/persistence/object/index.rb', line 270 def cursor( *args, & block ) cursor_instance = ::Persistence::Cursor.new( @parent_bucket, 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_keys_for_object!(object) ⇒ Object
Delete keys associated with object instance.
456 457 458 459 460 |
# File 'lib/persistence/object/index.rb', line 456 def delete_keys_for_object!( object ) return delete_keys_for_object_id!( object.persistence_id ) end |
#delete_keys_for_object_id!(global_id) ⇒ Object
Delete keys associated with object persistence ID.
471 472 473 474 475 |
# File 'lib/persistence/object/index.rb', line 471 def delete_keys_for_object_id!( global_id ) return adapter_index.delete_keys_for_object_id!( global_id ) end |
#disable ⇒ Object
Disable bucket. Used internally by port when port is disabled.
149 150 151 152 153 |
# File 'lib/persistence/object/index.rb', line 149 def disable @adapter_index = nil end |
#each {|object| ... } ⇒ Object
Iterate objects in current bucket.
314 315 316 317 318 |
# File 'lib/persistence/object/index.rb', line 314 def each( & block ) return atomic_cursor.each( & block ) end |
#get_object_id(key) ⇒ Object
Get object ID for key in index.
407 408 409 410 411 |
# File 'lib/persistence/object/index.rb', line 407 def get_object_id( key ) return adapter_index.get_object_id( key ) end |
#index_existing_objects ⇒ Object Also known as: sync_index
Index objects that currently exist in parent bucket.
329 330 331 332 333 334 335 336 337 |
# File 'lib/persistence/object/index.rb', line 329 def index_existing_objects @parent_bucket.each do |this_object| index_object( this_object ) end return self end |
#index_object(object, key) ⇒ Object
Index key for object instance.
424 425 426 427 428 |
# File 'lib/persistence/object/index.rb', line 424 def index_object( object, key ) return index_object_id( object.persistence_id, key ) end |
#index_object_id(global_id, key) ⇒ Object
Index key for object persistence ID.
441 442 443 444 445 |
# File 'lib/persistence/object/index.rb', line 441 def index_object_id( global_id, key ) return adapter_index.index_object_id( global_id, key ) end |
#init_sorting_procs(sorting_proc_or_sort_name, duplicates_sorting_proc_or_sort_name) ⇒ Object
Initializes sorting procs from procs or sorting method names.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/persistence/object/index.rb', line 168 def init_sorting_procs( sorting_proc_or_sort_name, duplicates_sorting_proc_or_sort_name ) if sorting_proc_or_sort_name if sorting_proc_or_sort_name.is_a?( ::Proc ) @sorting_procs = sorting_proc_or_sort_name else @sorting_procs = sorting_proc_for_sort_name( sorting_proc_or_sort_name ) end end if duplicates_sorting_proc_or_sort_name if duplicates_sorting_proc_or_sort_name.is_a?( ::Proc ) @duplicates_sorting_procs = duplicates_sorting_proc_or_sort_name else @duplicates_sorting_procs = sorting_proc_for_sort_name( sorting_proc_or_sort_name ) end end end |
#initialize(index_name, parent_bucket, permits_duplicates = nil, sorting_proc_or_sort_names = nil, duplicates_sorting_proc_or_sort_names = nil, ancestor_index_instance = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/persistence/object/index.rb', line 29 def initialize( index_name, parent_bucket, permits_duplicates = nil, sorting_proc_or_sort_names = nil, duplicates_sorting_proc_or_sort_names = nil, ancestor_index_instance = nil ) if index_name self.name = index_name end if ancestor_index_instance encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default ) encapsulation.register_child_for_parent( self, ancestor_index_instance ) end unless permits_duplicates.nil? self.permits_duplicates = permits_duplicates end if sorting_proc_or_sort_names or duplicates_sorting_proc_or_sort_names init_sorting_procs( sorting_proc_or_sort_names, duplicates_sorting_proc_or_sort_names ) end initialize_for_bucket( parent_bucket ) end |
#initialize_for_bucket(parent_bucket) ⇒ Object
Initialize for parent bucket.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/persistence/object/index.rb', line 102 def initialize_for_bucket( parent_bucket ) @parent_bucket = parent_bucket # object indexes are held and run by the classes/modules that define them # synchronize the index instance with the parent bucket's adapter instance if adapter_bucket = parent_bucket.instance_variable_get( :@adapter_bucket ) index_name = name if adapter_bucket.has_index?( index_name ) @adapter_index = adapter_bucket.index( index_name ) # if index has aleady been declared and permits_duplicates does not match, raise error # double ! ensures equality for false == nil if ! permits_duplicates? != ! @adapter_index.permits_duplicates? raise ::Persistence::Exception::ConflictingIndexAlreadyDeclared, 'Index ' + index_name.to_s + ' has already been declared, ' + 'and new duplicates declaration does not match existing declaration.' end else # get adapter index instance in adapter bucket @adapter_index = parent_bucket.adapter_bucket.create_index( index_name, permits_duplicates? ) end else parent_bucket.pend_index( self ) end end |
#name ⇒ Symbol, String
Index name
66 |
# File 'lib/persistence/object/index.rb', line 66 attr_setting :name |
#permits_duplicates? ⇒ true, false
Query whether index permits duplicates.
77 |
# File 'lib/persistence/object/index.rb', line 77 attr_setting :permits_duplicates? |
#persisted?(key) ⇒ true, false
Query whether key exists in index.
392 393 394 395 396 |
# File 'lib/persistence/object/index.rb', line 392 def persisted?( key ) return get_object_id( key ) ? true : false end |
#sorting_proc_for_sort_name(sort_name) ⇒ Proc
Get sorting proc associated with sorting method name. PENDING.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/persistence/object/index.rb', line 213 def sorting_proc_for_sort_name( sort_name ) raise 'Pending' sorting_proc = nil case sort_name when :alpha when :numeric when :alpha_numeric when :numeric_alpha when :upper_lower when :lower_upper when :upper_lower_numeric when :lower_upper_numeric when :numeric_upper_lower when :numeric_lower_upper when :reverse_alpha when :reverse_alpha_numeric when :reverse_numeric_alpha when :reverse_upper_lower_numeric when :reverse_lower_upper_numeric when :reverse_numeric_upper_lower when :reverse_numeric_lower_upper end return sorting_proc end |