Module: Persistence::Object::ClassInstance

Includes:
CascadingConfiguration::Hash, CascadingConfiguration::Setting, Enumerable, ParsePersistenceArgs
Defined in:
lib/persistence/object/class_instance.rb

Overview

Class methods for any objects enabled with persistence capabilities.

Instance Method Summary collapse

Methods included from ParsePersistenceArgs

#parse_args_for_index_value_no_value, #process_file_key

Instance Method Details

#all?(index_name = nil, &block) ⇒ Boolean

See Enumerable.

Returns:

  • (Boolean)


750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/persistence/object/class_instance.rb', line 750

def all?( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).all?( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#any?(index_name = nil, &block) ⇒ Boolean

See Enumerable.

Returns:

  • (Boolean)


771
772
773
774
775
776
777
778
779
780
781
782
783
# File 'lib/persistence/object/class_instance.rb', line 771

def any?( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).any?( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#block_index(index_name, ...) ⇒ Persistence::Object::Index::BlockIndex

Create a block index.

Parameters:

  • index_name

    Name of index.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



404
405
406
407
408
409
410
411
412
# File 'lib/persistence/object/class_instance.rb', line 404

def block_index( *index_names, & indexing_block )

  index_names.each do |this_index_name|
    instance = create_block_index( this_index_name, false, & indexing_block )
  end

  return self
  
end

#block_index_ordered(index_name, ordering_proc) {|object| ... } ⇒ Persistence::Object::Index::BlockIndex

Create an ordered block index. PENDING.

Parameters:

  • index_name

    Name of index.

  • ordering_proc

    Proc for determining sort order. See Array#sort_by.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



430
431
432
433
434
435
436
# File 'lib/persistence/object/class_instance.rb', line 430

def block_index_ordered( index_name, ordering_proc, & indexing_block )

  instance = create_block_index( index_name, true, ordering_proc, & indexing_block )

  return self

end

#block_index_ordered_with_duplicates(index_name, ordering_proc, duplicates_ordering_proc = nil) {|object| ... } ⇒ Persistence::Object::Index::BlockIndex

Create an ordered block index that permits duplicates. PENDING.

Parameters:

  • index_name

    Name of index.

  • ordering_proc

    Proc for determining sort order. See Array#sort_by.

  • duplicates_ordering_proc (defaults to: nil)

    Proc for determining sort order of duplicates. See Array#sort_by.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



483
484
485
486
487
488
489
490
491
492
493
# File 'lib/persistence/object/class_instance.rb', line 483

def block_index_ordered_with_duplicates( index_name, ordering_proc, duplicates_ordering_proc = nil, & indexing_block )
  
  raise 'Pending.'
  
  instance = create_block_index( index_name, true, ordering_proc, duplicates_ordering_proc, & indexing_block )

  indexes[ index_name ] = block_indexes[ index_name ] = instance

  return self

end

#block_index(index_name, ...) ⇒ Persistence::Object::Index::BlockIndex

Create a block index that permits duplicates.

Parameters:

  • index_name

    Name of index.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



454
455
456
457
458
459
460
461
462
463
# File 'lib/persistence/object/class_instance.rb', line 454

def block_index_with_duplicates( *index_names, & indexing_block )

  index_names.each do |this_index_name|
    this_instance = create_block_index( this_index_name, true, & indexing_block )
    indexes[ this_index_name ] = block_indexes[ this_index_name ] = this_instance
  end
  
  return self

end

#cease!(global_id) ⇒ Object? #cease!(index_name, key) ⇒ Object? #cease!(index_name_key_hash) ⇒ Object? #cease!(index_instance, key) ⇒ Object? #cease!(index_instance_key_hash) ⇒ Object?

Remove object properties stored for object ID from persistence bucket and indexes.

Overloads:

  • #cease!(global_id) ⇒ Object?

    Parameters:

    • global_id (Object)

      Object persistence ID.

  • #cease!(index_name, key) ⇒ Object?

    Parameters:

    • index_name (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #cease!(index_name_key_hash) ⇒ Object?

    Parameters:

    • index_name_key_hash (Hash{Symbol,String=>Object})

      Name of index for key-based retrieval.

  • #cease!(index_instance, key) ⇒ Object?

    Parameters:

    • index_instance (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #cease!(index_instance_key_hash) ⇒ Object?

    Parameters:

Returns:

  • (Object, nil)

    Persisted object.



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/persistence/object/class_instance.rb', line 318

def cease!( *args )
  
  # FIX - future: archive if appropriate (distinct from delete/etc. see draft spec)
  
  index, key, no_key = parse_args_for_index_value_no_value( args, true )

  global_id = index ? index.get_object_id( key ) : key

  indexes.each do |this_index_name, this_index|
    this_index.delete_keys_for_object_id!( global_id )
  end
  
  hash_in_port = instance_persistence_bucket.delete_object!( global_id )
  
  return hash_in_port
  
end

#chunk(index_name = nil, &block) ⇒ Object

See Enumerable.



792
793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/persistence/object/class_instance.rb', line 792

def chunk( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).chunk( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#collect(index_name = nil, &block) ⇒ Object

See Enumerable.



813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/persistence/object/class_instance.rb', line 813

def collect( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).collect( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#count(index_name = nil, *args, &block) ⇒ Object

See Enumerable.



1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
# File 'lib/persistence/object/class_instance.rb', line 1638

def count( index_name = nil, *args, & block )
  
  return_value = 0
  
  if index_name
    return_value = index( index_name, true ).count( *args, & block )
  else
    if block_given?
      return_value = super( & block )
    elsif args.empty?
      return_value = instance_persistence_bucket.count
    else
      return_value = super( *args )
    end
  end
  
  return return_value
  
end

#cursor(global_id) ⇒ Persistence::Adapter::Mock::Cursor #cursor(index_name, key) ⇒ Persistence::Adapter::Mock::Cursor #cursor(index, key) ⇒ Persistence::Adapter::Mock::Cursor

Create and return cursor instance for this bucket.

Overloads:

Returns:



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/persistence/object/class_instance.rb', line 715

def cursor( *args, & block )
  
  cursor_instance = nil
  
  index_instance, key, no_key = parse_args_for_index_value_no_value( args )
  
  if index_instance
    
    if no_key
      cursor_instance = index_instance.cursor( & block )
    else
      cursor_instance = index_instance.cursor( key, & block )        
    end
    
  else

    if no_key
      instance_persistence_bucket.cursor( & block )
    else
      instance_persistence_bucket.cursor( key, & block )
    end
    
  end
  
  return cursor_instance
  
end

#cycle(index_name = nil, item = nil, &block) ⇒ Object

See Enumerable.



857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/persistence/object/class_instance.rb', line 857

def cycle( index_name = nil, item = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).cycle( item, & block )
  else
    return_value = super( item, & block )
  end
  
  return return_value
  
end

#delete_index(index_name, ...) ⇒ Object

Delete index(es).

Parameters:

  • index_name

    Name of index to delete.

Returns:

  • self



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/persistence/object/class_instance.rb', line 668

def delete_index( *index_names )
  
  index_names.each do |this_index_name|

    this_index = indexes.delete( this_index_name )
    persistence_port.delete_index( self, this_index )

    case this_index
      when ::Persistence::Object::Index::Explicit
        explicit_indexes.delete( this_index_name )
      when ::Persistence::Object::Index::Block
        block_indexes.delete( this_index_name )
      when ::Persistence::Object::Index::Attribute
        attribute_indexes.delete( this_index_name )
    end

  end
  
  return self
  
end

#detect(index_name = nil, if_none = nil, &block) ⇒ Object

See Enumerable.



878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/persistence/object/class_instance.rb', line 878

def detect( index_name = nil, if_none = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).detect( if_none, & block )
  else
    return_value = super( if_none, & block )    
  end
  
  return return_value
  
end

#drop(index_name = nil, number = nil, &block) ⇒ Object

See Enumerable.



899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'lib/persistence/object/class_instance.rb', line 899

def drop( index_name = nil, number = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).drop( number, & block )
  else
    return_value = super( number, & block )   
  end
  
  return return_value
  
end

#drop_while(index_name = nil, &block) ⇒ Object

See Enumerable.



920
921
922
923
924
925
926
927
928
929
930
931
932
# File 'lib/persistence/object/class_instance.rb', line 920

def drop_while( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).drop_while( & block )
  else
    return_value = super( & block )  
  end
  
  return return_value
  
end

#each(index_name = nil, &block) ⇒ Object

See Enumerable.



941
942
943
944
945
946
947
948
949
950
951
952
953
# File 'lib/persistence/object/class_instance.rb', line 941

def each( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).each( & block )
  else
    return_value = instance_persistence_bucket.each( & block )
  end
  
  return return_value
  
end

#each_cons(index_name = nil, number = nil, &block) ⇒ Object

See Enumerable.



962
963
964
965
966
967
968
969
970
971
972
973
974
# File 'lib/persistence/object/class_instance.rb', line 962

def each_cons( index_name = nil, number = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).each_cons( number, & block )
  else
    return_value = super( number, & block )
  end
  
  return return_value
  
end

#each_slice(index_name = nil, slice_size = nil, &block) ⇒ Object

See Enumerable.



983
984
985
986
987
988
989
990
991
992
993
994
995
# File 'lib/persistence/object/class_instance.rb', line 983

def each_slice( index_name = nil, slice_size = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).each_cons( slice_size, & block )
  else
    return_value = super( slice_size, & block )     
  end
  
  return return_value
  
end

#each_with_index(index_name = nil, *args, &block) ⇒ Object

See Enumerable.



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/persistence/object/class_instance.rb', line 1004

def each_with_index( index_name = nil, *args, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).each_with_index( *args, & block )
  else
    return_value = super( *args, & block )
  end
  
  return return_value
  
end

#each_with_object(index_name = nil, object = nil, &block) ⇒ Object

See Enumerable.



1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/persistence/object/class_instance.rb', line 1025

def each_with_object( index_name = nil, object = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).each_with_object( object, & block )
  else
    return_value = super( object, & block )
  end
  
  return return_value
  
end

#entries(index_name = nil, &block) ⇒ Object

See Enumerable.



1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'lib/persistence/object/class_instance.rb', line 1046

def entries( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).entries( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#explicit_index(index_name, ...) ⇒ Persistence::Object::Index::BlockIndex

Create a explicit index.

Parameters:

  • index_name

    Name of index.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



536
537
538
539
540
541
542
543
544
545
# File 'lib/persistence/object/class_instance.rb', line 536

def explicit_index( *index_names )

  index_names.each do |this_index_name|
    instance = create_explicit_index( this_index_name, false )
    indexes[ this_index_name ] = explicit_indexes[ this_index_name ] = instance
  end
  
  return self

end

#explicit_index_ordered(index_name, ..., &ordering_block) ⇒ Persistence::Object::Index::BlockIndex

Create an ordered explicit index. PENDING.

Parameters:

  • index_name

    Name of index.

Yields:

  • (object)

    Block for determining sort order. See Array#sort_by.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/persistence/object/class_instance.rb', line 563

def explicit_index_ordered( *index_names, & ordering_block )
  
  raise 'Pending.'
  
  index_names.each do |this_index_name|
    instance = create_explicit_index( this_index_name, false, ordering_block )
    indexes[ this_index_name ] = explicit_indexes[ this_index_name ] = instance
  end
  
  return self

end

#explicit_index_ordered_with_duplicates(index_name, duplicates_ordering_proc = nil) {|object| ... } ⇒ Persistence::Object::Index::BlockIndex

Create an ordered explicit index that permits duplicates. PENDING.

Parameters:

  • index_name

    Name of index.

  • duplicates_ordering_proc (defaults to: nil)

    Proc for determining sort order of duplicates. See Array#sort_by.

Yields:

  • (object)

    Block for determining sort order. See Array#sort_by.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



619
620
621
622
623
624
625
626
627
628
# File 'lib/persistence/object/class_instance.rb', line 619

def explicit_index_ordered_with_duplicates( index_name, duplicates_ordering_proc = nil, & ordering_block )

  raise 'Pending.'

  instance = create_explicit_index( this_index_name, true, ordering_block, duplicates_ordering_proc )
  indexes[ index_name ] = explicit_indexes[ index_name ] = instance
  
  return self
  
end

#explicit_index(index_name, ...) ⇒ Persistence::Object::Index::BlockIndex

Create a explicit index that permits duplicates.

Parameters:

  • index_name

    Name of index.

Yields:

  • (object)

    Block to create index keys on object.

Yield Parameters:

  • object (Object)

    Object to index.

Returns:



592
593
594
595
596
597
598
599
600
601
# File 'lib/persistence/object/class_instance.rb', line 592

def explicit_index_with_duplicates( *index_names )

  index_names.each do |this_index_name|
    instance = create_explicit_index( this_index_name, true )
    indexes[ this_index_name ] = explicit_indexes[ this_index_name ] = instance
  end

  return self
  
end

#find(index_name = nil, if_none = nil, &block) ⇒ Object

See Enumerable.



1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/persistence/object/class_instance.rb', line 1067

def find( index_name = nil, if_none = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).find( if_none, & block )
  else
    return_value = super( if_none, & block )    
  end
  
  return return_value
  
end

#find_all(index_name = nil, &block) ⇒ Object

See Enumerable.



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
# File 'lib/persistence/object/class_instance.rb', line 1088

def find_all( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).find_all( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#find_index(index_name = nil, value = nil, &block) ⇒ Object

See Enumerable.



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'lib/persistence/object/class_instance.rb', line 1130

def find_index( index_name = nil, value = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).find_index( value, & block )
  else
    return_value = super( value, & block )
  end
  
  return return_value
  
end

#first(index_name = nil, number = nil, &block) ⇒ Object

See Enumerable.



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/persistence/object/class_instance.rb', line 1151

def first( index_name = nil, number = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).first( number, & block )
  else
    return_value = super( number, & block )
  end
  
  return return_value
  
end

#flat_map(index_name = nil, &block) ⇒ Object Also known as: collect_concat

See Enumerable.



835
836
837
838
839
840
841
842
843
844
845
846
847
# File 'lib/persistence/object/class_instance.rb', line 835

def flat_map( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).flat_map( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#grep(index_name = nil, pattern = nil, &block) ⇒ Object

See Enumerable.



1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/persistence/object/class_instance.rb', line 1172

def grep( index_name = nil, pattern = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).grep( pattern, & block )
  else
    return_value = super( pattern, & block )
  end
  
  return return_value
  
end

#group_by(index_name = nil, &block) ⇒ Object

See Enumerable.



1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/persistence/object/class_instance.rb', line 1193

def group_by( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).group_by( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#has_block_index?(*index_names) ⇒ true, false

Query whether block index(es) exist for object.

overload( index_name, … )

@param index_name Name of requested index.

Returns:

  • (true, false)

    Whether index(es) exist.



508
509
510
511
512
513
514
515
516
517
518
# File 'lib/persistence/object/class_instance.rb', line 508

def has_block_index?( *index_names )
  
  has_index = false
  
  index_names.each do |this_index_name|
    break unless has_index = block_indexes.has_key?( this_index_name )
  end
  
  return has_index

end

#has_explicit_index?(*index_names) ⇒ true, false

Query whether explicit index(es) exist for object.

overload( index_name, … )

@param index_name Name of requested index.

Returns:

  • (true, false)

    Whether index(es) exist.



643
644
645
646
647
648
649
650
651
652
653
# File 'lib/persistence/object/class_instance.rb', line 643

def has_explicit_index?( *index_names )
  
  has_index = false
  
  index_names.each do |index_name|
    break unless has_index = explicit_indexes.has_key?( index_name )
  end
  
  return has_index
  
end

#has_index?(index_name, ...) ⇒ true, false

Query whether index(es) exist for object.

Parameters:

  • index_name

    Name of requested index.

Returns:

  • (true, false)

    Whether index(es) exist.



376
377
378
379
380
381
382
383
384
385
386
# File 'lib/persistence/object/class_instance.rb', line 376

def has_index?( *index_names )
  
  has_index = false
  
  index_names.each do |this_index_name|
    break unless has_index = indexes.has_key?( this_index_name )
  end
  
  return has_index

end

#include?(index_name = nil, object = nil, &block) ⇒ Boolean Also known as: member?

See Enumerable.

Returns:

  • (Boolean)


1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
# File 'lib/persistence/object/class_instance.rb', line 1215

def include?( index_name = nil, object = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).include?( object, & block )
  else
    return_value = super( object, & block )
  end
  
  return return_value
  
end

#index(index_name, ensure_exists = false) ⇒ Persistence::Object::Index?

Get index with given name.

Parameters:

  • index_name

    Name of requested index.

  • ensure_exists (defaults to: false)

    Throw exception if index does not exist.

Returns:



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/persistence/object/class_instance.rb', line 349

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 indexes[ index_name ]

end

#inject(index_name = nil, initial = nil, sym = nil, &block) ⇒ Object Also known as: reduce

See Enumerable.



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/persistence/object/class_instance.rb', line 1238

def inject( index_name = nil, initial = nil, sym = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).inject( initial, sym, & block )
  else
    return_value = super( initial, sym, & block )
  end
  
  return return_value
  
end

#instance_persistence_bucketPersistence::Port?

Get persistence bucket that will be used with instances of this object. Will use name of class if bucket

does not already exist.

Returns:



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/persistence/object/class_instance.rb', line 172

def instance_persistence_bucket

  bucket_instance = nil
  
  encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default )
  
  unless bucket_instance = encapsulation.get_configuration( self, :instance_persistence_bucket )
    self.instance_persistence_bucket = to_s
    bucket_instance = super
  end
  
  return bucket_instance
  
end

#instance_persistence_bucket=(bucket_name) ⇒ Object #instance_persistence_bucket=(bucket_instance) ⇒ Object Also known as: store_as, persists_in

Assign a persistence bucket to be used with instances of this object.

Overloads:

  • #instance_persistence_bucket=(bucket_name) ⇒ Object

    Parameters:

    • port_name (Symbol, String)

      Name of port to be used. Expects port by name to be available in Persistence controller.

  • #instance_persistence_bucket=(bucket_instance) ⇒ Object

    Parameters:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/persistence/object/class_instance.rb', line 124

def instance_persistence_bucket=( persistence_bucket_class_or_name )
  
  bucket = nil

  case persistence_bucket_class_or_name
    
    when nil

      bucket = super( nil )
    
    when ::String, ::Symbol
    
      if port = instance_persistence_port
        bucket = super( port.persistence_bucket( persistence_bucket_class_or_name.to_s ) )
      else
        bucket = super( ::Persistence.pending_bucket( self, persistence_bucket_class_or_name.to_s ) )
      end
    
    when ::Persistence::Bucket
    
      bucket = super( persistence_bucket_class_or_name )
    
    else

      if persistence_bucket_class_or_name.respond_to?( :persistence_bucket )
        bucket = super( persistence_bucket_class_or_name.persistence_bucket )
      end
    
  end

  return bucket
  
end

#instance_persistence_portPersistence::Port?

Get persistence port that will be used with instances of this object. Will use current port if available and

no port is assigned.

Returns:



98
99
100
101
102
# File 'lib/persistence/object/class_instance.rb', line 98

def instance_persistence_port

  return super || ( self.instance_persistence_port = ::Persistence.current_port )
  
end

#instance_persistence_port=(port_name) ⇒ Object #instance_persistence_port=(port_instance) ⇒ Object Also known as: store_using, persists_using

Assign a persistence port to be used with instances of this object.

Overloads:

  • #instance_persistence_port=(port_name) ⇒ Object

    Parameters:

    • port_name

      Name of port to be used. Expects port by name to be available in Persistence controller.

  • #instance_persistence_port=(port_instance) ⇒ Object

    Parameters:

    • port_instance

      Port instance to use.



33
34
35
36
37
38
39
40
41
42
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/persistence/object/class_instance.rb', line 33

def instance_persistence_port=( port_object_port_or_port_name )

  port = nil
  
  case port_object_port_or_port_name
    
    when nil

      port = super( nil )
    
    when ::Persistence::Port
    
      port = super( port_object_port_or_port_name )

    when ::Symbol, ::String
    
      port = super( ::Persistence.port_for_name_or_port( port_object_port_or_port_name, true ) )
    
    else

      if port_object_port_or_port_name.respond_to?( :instance_persistence_port )

        # if arg responds to :instance_persistence_port we use arg's instance port
        port = super( port_object_port_or_port_name.instance_persistence_port )

      elsif port_object_port_or_port_name.respond_to?( :persistence_port )

        # if arg responds to :persistence_port we use arg's port
        port = super( port_object_port_or_port_name.persistence_port )

      end
    
  end
  
  if port
    # check encapsulation for instance persistence bucket - that way we avoid creating a loop
    encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default )
    if bucket = encapsulation.get_configuration( self, :instance_persistence_bucket )
      if port.enabled?
        bucket.initialize_for_port( port )
      else
        bucket.disable
      end
    end
    port.register_instance( self )
  end
  
  return port
  
end

#map(index_name = nil, &block) ⇒ Object

See Enumerable.



1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
# File 'lib/persistence/object/class_instance.rb', line 1260

def map( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).map( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#max(index_name = nil, &block) ⇒ Object

See Enumerable.



1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/persistence/object/class_instance.rb', line 1281

def max( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).max( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#max_by(index_name = nil, &block) ⇒ Object

See Enumerable.



1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File 'lib/persistence/object/class_instance.rb', line 1302

def max_by( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).max_by( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#min_by(index_name = nil, &block) ⇒ Object

See Enumerable.



1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
# File 'lib/persistence/object/class_instance.rb', line 1323

def min_by( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).min_by( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#minmax(index_name = nil, &block) ⇒ Object

See Enumerable.



1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
# File 'lib/persistence/object/class_instance.rb', line 1344

def minmax( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).minmax( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#minmax_by(index_name = nil, &block) ⇒ Object

See Enumerable.



1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
# File 'lib/persistence/object/class_instance.rb', line 1365

def minmax_by( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).minmax_by( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#none?(index_name = nil, &block) ⇒ Boolean

See Enumerable.

Returns:

  • (Boolean)


1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/persistence/object/class_instance.rb', line 1386

def none?( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).none?( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#one?(index_name = nil, &block) ⇒ Boolean

See Enumerable.

Returns:

  • (Boolean)


1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
# File 'lib/persistence/object/class_instance.rb', line 1407

def one?( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).one?( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#partition(index_name = nil, &block) ⇒ Object

See Enumerable.



1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
# File 'lib/persistence/object/class_instance.rb', line 1428

def partition( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).partition( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#persist(global_id) ⇒ Object? #persist(index_name, key) ⇒ Object? #persist(index_name_key_hash) ⇒ Object? #persist(index_instance, key) ⇒ Object? #persist(index_instance_key_hash) ⇒ Object?

Retrieve object from persistence port.

Overloads:

  • #persist(global_id) ⇒ Object?

    Parameters:

    • global_id (Object)

      Object persistence ID.

  • #persist(index_name, key) ⇒ Object?

    Parameters:

    • index_name (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #persist(index_name_key_hash) ⇒ Object?

    Parameters:

    • index_name_key_hash (Hash{Symbol,String=>Object})

      Name of index for key-based retrieval.

  • #persist(index_instance, key) ⇒ Object?

    Parameters:

    • index_instance (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #persist(index_instance_key_hash) ⇒ Object?

    Parameters:

Returns:

  • (Object, nil)

    Persisted object.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/persistence/object/class_instance.rb', line 219

def persist( *args )

  persistence_value = nil

  index_instance, key, no_key = parse_args_for_index_value_no_value( args )

  # if no key, open a cursor for a list
  if no_key

    persistence_value = ::Persistence::Cursor.new( instance_persistence_bucket, index_instance )

  else

    global_id = index_instance ? index_instance.get_object_id( key ) : key
    
    persistence_value = instance_persistence_port.get_object( global_id )

  end
  
  return persistence_value

end

#persist_any(count) ⇒ Object+ #persist_any(: index, count) ⇒ Object+

Persist any object in cursor context.

Overloads:

  • #persist_any(count) ⇒ Object+

    Parameters:

    • count (Integer)

      How many objects to persist from cursor context.

Returns:



1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
# File 'lib/persistence/object/class_instance.rb', line 1759

def persist_any( *index_name_and_or_count )

  objects = nil
  index_name = nil
  count = 1
  
  case index_name_and_or_count[ 0 ]
    when Symbol, String
      index_name = index_name_or_count
      count_or_nil = index_name_and_or_count[ 1 ]
      case count_or_nil
        when Integer
          count = count_or_nil
      end
    when Integer
      count = index_name_or_count
  end
  
  if index_name
    objects = index( index_name ).cursor.any( count )
  else
    objects = instance_persistence_bucket.cursor.any( count )    
  end
  
  return objects
  
end

#persist_first(count) ⇒ Object+ #persist_first(: index, count) ⇒ Object+

Persist first object in cursor context.

Overloads:

  • #persist_first(count) ⇒ Object+

    Parameters:

    • count (Integer)

      How many objects to persist from start of cursor context.

Returns:



1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
# File 'lib/persistence/object/class_instance.rb', line 1673

def persist_first( *index_name_and_or_count )
  
  objects = nil
  index_name = nil
  count = 1
  
  case index_name_or_count = index_name_and_or_count[ 0 ]
    when Symbol, String
      index_name = index_name_or_count
      count_or_nil = index_name_and_or_count[ 1 ]
      case count_or_nil
        when Integer
          count = count_or_nil
      end
    when Integer
      count = index_name_or_count
  end

  if index_name
    objects = index( index_name ).cursor.first( count )
  else
    objects = instance_persistence_bucket.cursor.first( count )
  end
  
  return objects
  
end

#persist_last(count) ⇒ Object+ #persist_last(: index, count) ⇒ Object+

Persist last object in cursor context.

Overloads:

  • #persist_last(count) ⇒ Object+

    Parameters:

    • count (Integer)

      How many objects to persist from end of cursor context.

Returns:



1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
# File 'lib/persistence/object/class_instance.rb', line 1716

def persist_last( *index_name_and_or_count )
  
  objects = nil
  index_name = nil
  count = 1
  
  case index_name_and_or_count[ 0 ]
    when Symbol, String
      index_name = index_name_or_count
      count_or_nil = index_name_and_or_count[ 1 ]
      case count_or_nil
        when Integer
          count = count_or_nil
      end
    when Integer
      count = index_name_or_count
  end
  
  if index_name
    objects = index( index_name ).cursor.last( count )
  else
    objects = instance_persistence_bucket.cursor.last( count )
  end
  
  return objects
  
end

#persisted?(global_id) ⇒ true, false #persisted?(index_name, key) ⇒ true, false #persisted?(index_name_key_hash) ⇒ true, false #persisted?(index_instance, key) ⇒ true, false #persisted?(index_instance_key_hash) ⇒ true, false

Query whether object is persisted in port.

Overloads:

  • #persisted?(global_id) ⇒ true, false

    Parameters:

    • global_id (Object)

      Object persistence ID.

  • #persisted?(index_name, key) ⇒ true, false

    Parameters:

    • index_name (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #persisted?(index_name_key_hash) ⇒ true, false

    Parameters:

    • index_name_key_hash (Hash{Symbol,String=>Object})

      Name of index for key-based retrieval.

  • #persisted?(index_instance, key) ⇒ true, false

    Parameters:

    • index_instance (Symbol, String)

      Name of index for key-based retrieval.

    • key (Object)

      Key for retrieving object ID.

  • #persisted?(index_instance_key_hash) ⇒ true, false

    Parameters:

Returns:

  • (true, false)

    Whether object is persisted.



274
275
276
277
278
279
280
281
282
# File 'lib/persistence/object/class_instance.rb', line 274

def persisted?( *args )
  
  index, key, no_key = parse_args_for_index_value_no_value( args, true )
  
  global_id = index ? index.get_object_id( key ) : key
  
  return instance_persistence_port.get_bucket_name_for_object_id( global_id ) ? true : false

end

#reject(index_name = nil, &block) ⇒ Object

See Enumerable.



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
# File 'lib/persistence/object/class_instance.rb', line 1449

def reject( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).reject( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#reverse_each(index_name = nil, *args, &block) ⇒ Object

See Enumerable.



1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'lib/persistence/object/class_instance.rb', line 1470

def reverse_each( index_name = nil, *args, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).reverse_each( *args, & block )
  else
    return_value = super( *args, & block )
  end
  
  return return_value
  
end

#select(index_name = nil, &block) ⇒ Object

See Enumerable.



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/persistence/object/class_instance.rb', line 1109

def select( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).select( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#slice_before(index_name = nil, pattern = nil, &block) ⇒ Object

See Enumerable.



1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
# File 'lib/persistence/object/class_instance.rb', line 1491

def slice_before( index_name = nil, pattern = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).slice_before( pattern, & block )
  else
    return_value = super( pattern, & block )
  end
  
  return return_value
  
end

#sort(index_name = nil, &block) ⇒ Object

See Enumerable.



1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
# File 'lib/persistence/object/class_instance.rb', line 1512

def sort( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).sort( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#sort_by(index_name = nil, &block) ⇒ Object

See Enumerable.



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
# File 'lib/persistence/object/class_instance.rb', line 1533

def sort_by( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).sort_by( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#take(index_name = nil, number = nil, &block) ⇒ Object

See Enumerable.



1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
# File 'lib/persistence/object/class_instance.rb', line 1596

def take( index_name = nil, number = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).take( number, & block )
  else
    return_value = super( number, & block )
  end
  
  return return_value
  
end

#take_while(index_name = nil, &block) ⇒ Object

See Enumerable.



1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
# File 'lib/persistence/object/class_instance.rb', line 1554

def take_while( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).take_while( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#to_a(index_name = nil, &block) ⇒ Object

See Enumerable.



1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
# File 'lib/persistence/object/class_instance.rb', line 1575

def to_a( index_name = nil, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).to_a( & block )
  else
    return_value = super( & block )    
  end
  
  return return_value
  
end

#zip(index_name = nil, *args, &block) ⇒ Object

See Enumerable.



1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
# File 'lib/persistence/object/class_instance.rb', line 1617

def zip( index_name = nil, *args, & block )
  
  return_value = nil
  
  if index_name
    return_value = index( index_name ).zip( *args, & block )
  else
    return_value = super( *args, & block )
  end
  
  return return_value
  
end