Module: Persistence::Object::ClassInstance

Includes:
CascadingConfiguration::Hash, CascadingConfiguration::Setting, Enumerable, ParsePersistenceArgs::ClassInstance
Included in:
Complex
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::ClassInstance

#parse_class_args_for_index_value_no_value

Methods included from ParsePersistenceArgs

#process_file_key

Instance Method Details

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

See Enumerable.

Returns:

  • (Boolean)

754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/persistence/object/class_instance.rb', line 754

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)

775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'lib/persistence/object/class_instance.rb', line 775

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:


408
409
410
411
412
413
414
415
416
# File 'lib/persistence/object/class_instance.rb', line 408

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:


434
435
436
437
438
439
440
# File 'lib/persistence/object/class_instance.rb', line 434

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:


487
488
489
490
491
492
493
494
495
496
497
# File 'lib/persistence/object/class_instance.rb', line 487

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:


458
459
460
461
462
463
464
465
466
467
# File 'lib/persistence/object/class_instance.rb', line 458

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_class_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.


796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/persistence/object/class_instance.rb', line 796

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.


817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'lib/persistence/object/class_instance.rb', line 817

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.


1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
# File 'lib/persistence/object/class_instance.rb', line 1642

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:


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

def cursor( *args, & block )
  
  cursor_instance = nil
  
  index_instance, key, no_key = parse_class_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.


861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/persistence/object/class_instance.rb', line 861

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


672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/persistence/object/class_instance.rb', line 672

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.


882
883
884
885
886
887
888
889
890
891
892
893
894
# File 'lib/persistence/object/class_instance.rb', line 882

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.


903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/persistence/object/class_instance.rb', line 903

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.


924
925
926
927
928
929
930
931
932
933
934
935
936
# File 'lib/persistence/object/class_instance.rb', line 924

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.


945
946
947
948
949
950
951
952
953
954
955
956
957
# File 'lib/persistence/object/class_instance.rb', line 945

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.


966
967
968
969
970
971
972
973
974
975
976
977
978
# File 'lib/persistence/object/class_instance.rb', line 966

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.


987
988
989
990
991
992
993
994
995
996
997
998
999
# File 'lib/persistence/object/class_instance.rb', line 987

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.


1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'lib/persistence/object/class_instance.rb', line 1008

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.


1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/persistence/object/class_instance.rb', line 1029

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.


1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/persistence/object/class_instance.rb', line 1050

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:


540
541
542
543
544
545
546
547
548
549
# File 'lib/persistence/object/class_instance.rb', line 540

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:


567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/persistence/object/class_instance.rb', line 567

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:


623
624
625
626
627
628
629
630
631
632
# File 'lib/persistence/object/class_instance.rb', line 623

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:


596
597
598
599
600
601
602
603
604
605
# File 'lib/persistence/object/class_instance.rb', line 596

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.


1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
# File 'lib/persistence/object/class_instance.rb', line 1071

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.


1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'lib/persistence/object/class_instance.rb', line 1092

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.


1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
# File 'lib/persistence/object/class_instance.rb', line 1134

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.


1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/persistence/object/class_instance.rb', line 1155

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.


839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/persistence/object/class_instance.rb', line 839

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.


1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
# File 'lib/persistence/object/class_instance.rb', line 1176

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.


1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
# File 'lib/persistence/object/class_instance.rb', line 1197

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.


512
513
514
515
516
517
518
519
520
521
522
# File 'lib/persistence/object/class_instance.rb', line 512

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.


647
648
649
650
651
652
653
654
655
656
657
# File 'lib/persistence/object/class_instance.rb', line 647

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.


380
381
382
383
384
385
386
387
388
389
390
# File 'lib/persistence/object/class_instance.rb', line 380

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)

1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'lib/persistence/object/class_instance.rb', line 1219

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
362
363
364
365
# File 'lib/persistence/object/class_instance.rb', line 349

def index( index_name, ensure_exists = false )
   
   index_instance = nil
   
   if index_name.nil?
     raise ::ArgumentError, 'Index name required but received nil.'
   end
   
   unless index_instance = indexes[ index_name ]
     if ensure_exists
       raise ::ArgumentError, 'No index found by name ' << index_name.to_s + ' for ' << 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.


1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
# File 'lib/persistence/object/class_instance.rb', line 1242

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.


1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'lib/persistence/object/class_instance.rb', line 1264

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.


1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
# File 'lib/persistence/object/class_instance.rb', line 1285

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.


1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
# File 'lib/persistence/object/class_instance.rb', line 1306

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.


1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
# File 'lib/persistence/object/class_instance.rb', line 1327

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.


1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File 'lib/persistence/object/class_instance.rb', line 1348

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.


1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# File 'lib/persistence/object/class_instance.rb', line 1369

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)

1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
# File 'lib/persistence/object/class_instance.rb', line 1390

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)

1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/persistence/object/class_instance.rb', line 1411

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.


1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
# File 'lib/persistence/object/class_instance.rb', line 1432

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_class_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_bucket.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:


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

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:


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

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:


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

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_class_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.


1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'lib/persistence/object/class_instance.rb', line 1453

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.


1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
# File 'lib/persistence/object/class_instance.rb', line 1474

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.


1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
# File 'lib/persistence/object/class_instance.rb', line 1113

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.


1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
# File 'lib/persistence/object/class_instance.rb', line 1495

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.


1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
# File 'lib/persistence/object/class_instance.rb', line 1516

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.


1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
# File 'lib/persistence/object/class_instance.rb', line 1537

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.


1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
# File 'lib/persistence/object/class_instance.rb', line 1600

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.


1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
# File 'lib/persistence/object/class_instance.rb', line 1558

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.


1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
# File 'lib/persistence/object/class_instance.rb', line 1579

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.


1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
# File 'lib/persistence/object/class_instance.rb', line 1621

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