persistence 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/lib/persistence.rb +0 -1
  2. data/lib/persistence/adapter/abstract.rb +1 -1
  3. data/lib/persistence/adapter/abstract/enable_disable.rb +1 -1
  4. data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +1 -1
  5. data/lib/persistence/adapter/abstract/primary_key/simple.rb +1 -1
  6. data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +1 -1
  7. data/lib/persistence/cursor/atomic.rb +2 -2
  8. data/lib/persistence/object.rb +1 -1
  9. data/lib/persistence/object/autodetermine.rb +5 -4
  10. data/lib/persistence/object/class_instance.rb +12 -8
  11. data/lib/persistence/object/complex.rb +4 -4
  12. data/lib/persistence/object/complex/array.rb +6 -4
  13. data/lib/persistence/object/complex/array/class_instance.rb +1 -1
  14. data/lib/persistence/object/complex/array/object_instance.rb +1 -1
  15. data/lib/persistence/object/complex/attributes/attributes_array.rb +1 -1
  16. data/lib/persistence/object/complex/hash.rb +6 -4
  17. data/lib/persistence/object/complex/hash/class_instance.rb +1 -1
  18. data/lib/persistence/object/complex/hash/object_instance.rb +1 -1
  19. data/lib/persistence/object/complex/object_instance.rb +3 -3
  20. data/lib/persistence/object/flat.rb +6 -5
  21. data/lib/persistence/object/flat/class_instance.rb +2 -2
  22. data/lib/persistence/object/flat/file.rb +4 -3
  23. data/lib/persistence/object/flat/file/class_instance.rb +23 -30
  24. data/lib/persistence/object/flat/file/file_persistence.rb +4 -53
  25. data/lib/persistence/object/flat/file/object_instance.rb +21 -42
  26. data/lib/persistence/object/index.rb +0 -1
  27. data/lib/persistence/object/index_hash.rb +1 -1
  28. data/lib/persistence/object/object_instance.rb +11 -11
  29. data/lib/persistence/object/parse_persistence_args.rb +2 -108
  30. data/lib/persistence/object/parse_persistence_args/class_instance.rb +124 -0
  31. data/lib/persistence/object/parse_persistence_args/object_instance.rb +124 -0
  32. data/lib/persistence/port/bucket/bucket_interface.rb +0 -18
  33. data/lib/persistence/port/port_interface.rb +1 -19
  34. data/lib/requires.rb +10 -9
  35. data/spec/persistence/object/complex/attributes_spec.rb +1 -140
  36. data/spec/persistence/object/flat/bignum_spec.rb +12 -4
  37. data/spec/persistence/object/flat/class_spec.rb +9 -4
  38. data/spec/persistence/object/flat/file/class_instance_spec.rb +0 -1
  39. data/spec/persistence/object/flat/file_spec.rb +6 -9
  40. data/spec/persistence/object/indexes/block_index_spec.rb +1 -1
  41. data/spec/persistence/object/parse_persistence_args/class_instance_spec.rb +61 -0
  42. data/spec/persistence/object/parse_persistence_args/object_instance_spec.rb +63 -0
  43. data/spec/persistence/object_spec.rb +48 -82
  44. data/spec/persistence/port/bucket/index/bucket_index_spec.rb +1 -0
  45. data/spec/{Persistence_spec.rb → persistence_spec.rb} +0 -0
  46. metadata +8 -5
  47. data/spec/persistence/object/parse_persistence_args_spec.rb +0 -65
@@ -29,7 +29,6 @@ module ::Persistence
29
29
  extend ::Persistence::Object::Flat::File::FilePersistence
30
30
 
31
31
  persist_files_by_path!
32
- persist_file_paths_as_strings!
33
32
 
34
33
  end
35
34
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  ###
3
3
  # @private
4
- ###
4
+ #
5
5
  # Singleton providing helper methods for writing adapters.
6
6
  #
7
7
  module ::Persistence::Adapter::Abstract
@@ -1,7 +1,7 @@
1
1
 
2
2
  ###
3
3
  # @private
4
- ###
4
+ #
5
5
  # Provides home directory and enable/disable methods to including adapter class instances.
6
6
  #
7
7
  module ::Persistence::Adapter::Abstract::EnableDisable
@@ -1,7 +1,7 @@
1
1
 
2
2
  ###
3
3
  # @private
4
- ###
4
+ #
5
5
  # Provides primary key with the object's persistence_id and the attribute name, connected by
6
6
  # self.class::Delimiter in including adapter class.
7
7
  #
@@ -1,7 +1,7 @@
1
1
 
2
2
  ###
3
3
  # @private
4
- ###
4
+ #
5
5
  # Provides primary key with attribute name to including adapter class.
6
6
  #
7
7
  module ::Persistence::Adapter::Abstract::PrimaryKey::Simple
@@ -136,7 +136,7 @@ module ::Persistence::Adapter::Mock::Bucket::Index::IndexInterface
136
136
 
137
137
  index_value_or_keys = @reverse_keys.delete( global_id )
138
138
 
139
- if index_value_or_keys.is_a?( Array )
139
+ if index_value_or_keys.is_a?( ::Array )
140
140
 
141
141
  index_value_or_keys.each do |this_key|
142
142
  @keys.delete( this_key )
@@ -61,7 +61,7 @@ module ::Persistence::Cursor::Atomic
61
61
  #
62
62
  def first( count = 1 )
63
63
  first_values = super
64
- if first_values.is_a?( Array )
64
+ if first_values.is_a?( ::Array )
65
65
  first_values.each do |this_value|
66
66
  this_value.attrs_atomic!
67
67
  end
@@ -97,7 +97,7 @@ module ::Persistence::Cursor::Atomic
97
97
  #
98
98
  def next( count = 1 )
99
99
  next_values = super
100
- if next_values.is_a?( Array )
100
+ if next_values.is_a?( ::Array )
101
101
  next_values.each do |this_value|
102
102
  this_value.attrs_atomic!
103
103
  end
@@ -17,5 +17,5 @@
17
17
  module ::Persistence::Object
18
18
 
19
19
  extend ::Persistence::Object::Autodetermine
20
-
20
+
21
21
  end
@@ -1,10 +1,11 @@
1
1
 
2
2
  ###
3
3
  # @private
4
- ###
4
+ #
5
5
  # Module used internally to extend Persistence and Persistence::Object to automatically determine what type of object
6
6
  # (of types: Complex, Flat, Hash, Array, File) module is being included in, and to include the appropriate
7
7
  # corresponding module branch.
8
+ #
8
9
  module ::Persistence::Object::Autodetermine
9
10
 
10
11
  ###################
@@ -13,9 +14,9 @@ module ::Persistence::Object::Autodetermine
13
14
 
14
15
  def self.extended( persistence_object_module )
15
16
 
16
- persistence_object_module.extend ModuleCluster::Define::Block::ClassOrModuleOrInstance
17
+ persistence_object_module.extend( ::Module::Cluster )
17
18
 
18
- persistence_object_module.class_or_module_include do |class_or_module|
19
+ persistence_object_module.cluster( :persistence ).after_include do |class_or_module|
19
20
 
20
21
  # two types of objects: complex and flat
21
22
  # * complex objects persist ivars
@@ -65,7 +66,7 @@ module ::Persistence::Object::Autodetermine
65
66
 
66
67
  end
67
68
 
68
- persistence_object_module.class_or_module_or_instance_extend do
69
+ persistence_object_module.cluster( :persistence ).before_extend( :class, :module ) do
69
70
  raise 'Persistence does not expect to be used without class-level support.'
70
71
  end
71
72
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
  module ::Persistence::Object::ClassInstance
6
6
 
7
- include ::Persistence::Object::ParsePersistenceArgs
7
+ include ::Persistence::Object::ParsePersistenceArgs::ClassInstance
8
8
 
9
9
  include ::CascadingConfiguration::Setting
10
10
  include ::CascadingConfiguration::Hash
@@ -220,7 +220,7 @@ module ::Persistence::Object::ClassInstance
220
220
 
221
221
  persistence_value = nil
222
222
 
223
- index_instance, key, no_key = parse_args_for_index_value_no_value( args )
223
+ index_instance, key, no_key = parse_class_args_for_index_value_no_value( args )
224
224
 
225
225
  # if no key, open a cursor for a list
226
226
  if no_key
@@ -231,7 +231,7 @@ module ::Persistence::Object::ClassInstance
231
231
 
232
232
  global_id = index_instance ? index_instance.get_object_id( key ) : key
233
233
 
234
- persistence_value = instance_persistence_port.get_object( global_id )
234
+ persistence_value = instance_persistence_bucket.get_object( global_id )
235
235
 
236
236
  end
237
237
 
@@ -273,7 +273,7 @@ module ::Persistence::Object::ClassInstance
273
273
  #
274
274
  def persisted?( *args )
275
275
 
276
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
276
+ index, key, no_key = parse_class_args_for_index_value_no_value( args, true )
277
277
 
278
278
  global_id = index ? index.get_object_id( key ) : key
279
279
 
@@ -319,7 +319,7 @@ module ::Persistence::Object::ClassInstance
319
319
 
320
320
  # FIX - future: archive if appropriate (distinct from delete/etc. see draft spec)
321
321
 
322
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
322
+ index, key, no_key = parse_class_args_for_index_value_no_value( args, true )
323
323
 
324
324
  global_id = index ? index.get_object_id( key ) : key
325
325
 
@@ -349,10 +349,14 @@ module ::Persistence::Object::ClassInstance
349
349
  def index( index_name, ensure_exists = false )
350
350
 
351
351
  index_instance = nil
352
-
352
+
353
+ if index_name.nil?
354
+ raise ::ArgumentError, 'Index name required but received nil.'
355
+ end
356
+
353
357
  unless index_instance = indexes[ index_name ]
354
358
  if ensure_exists
355
- raise ::ArgumentError, 'No index found by name ' << index_name.to_s + '.'
359
+ raise ::ArgumentError, 'No index found by name ' << index_name.to_s + ' for ' << to_s + '.'
356
360
  end
357
361
  end
358
362
 
@@ -716,7 +720,7 @@ module ::Persistence::Object::ClassInstance
716
720
 
717
721
  cursor_instance = nil
718
722
 
719
- index_instance, key, no_key = parse_args_for_index_value_no_value( args )
723
+ index_instance, key, no_key = parse_class_args_for_index_value_no_value( args )
720
724
 
721
725
  if index_instance
722
726
 
@@ -6,12 +6,12 @@
6
6
  #
7
7
  module ::Persistence::Object::Complex
8
8
 
9
- extend ModuleCluster::Define::ClusterCascades
9
+ extend ::Module::Cluster
10
10
 
11
11
  include ::Persistence::Object::ObjectInstance
12
- include_or_extend_cascades_prepend_extends ::Persistence::Object::ClassInstance
13
-
14
12
  include ::Persistence::Object::Complex::ObjectInstance
15
- include_or_extend_cascades_prepend_extends ::Persistence::Object::Complex::ClassInstance
13
+
14
+ cluster( :persistence ).before_include_or_extend.cascade.extend( ::Persistence::Object::ClassInstance,
15
+ ::Persistence::Object::Complex::ClassInstance )
16
16
 
17
17
  end
@@ -1,14 +1,16 @@
1
1
 
2
2
  ###
3
- # Convenience module for extending array types (singletons and instances) with persistence capabilities.
3
+ # Convenience module for extending array types (singletons and instances)
4
+ # with persistence capabilities.
4
5
  #
5
6
  module ::Persistence::Object::Complex::Array
6
7
 
7
- extend ModuleCluster::Define::ClusterCascades
8
+ extend ::Module::Cluster
8
9
 
9
10
  include ::Persistence::Object::Complex
10
-
11
11
  include ::Persistence::Object::Complex::Array::ObjectInstance
12
- include_or_extend_cascades_prepend_extends ::Persistence::Object::Complex::Array::ClassInstance
12
+
13
+ cascade = cluster( :persistence ).before_include_or_extend.cascade
14
+ cascade.extend( ::Persistence::Object::Complex::Array::ClassInstance )
13
15
 
14
16
  end
@@ -10,7 +10,7 @@ module ::Persistence::Object::Complex::Array::ClassInstance
10
10
 
11
11
  def persist( *args )
12
12
 
13
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
13
+ index, key, no_key = parse_class_args_for_index_value_no_value( args, true )
14
14
 
15
15
  if index
16
16
  global_id = index.get_object_id( key )
@@ -10,7 +10,7 @@ module ::Persistence::Object::Complex::Array::ObjectInstance
10
10
 
11
11
  def persist( *args )
12
12
 
13
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
13
+ index, key, no_key = parse_object_args_for_index_value_no_value( args, true )
14
14
 
15
15
  if index
16
16
  global_id = index.get_object_id( key )
@@ -20,7 +20,7 @@ module ::Persistence::Object::Complex::Attributes::AttributesArray
20
20
  def has_attributes?( *attributes )
21
21
 
22
22
  has_attributes = false
23
-
23
+
24
24
  attributes.each do |this_attribute|
25
25
  break unless has_attributes = include?( this_attribute )
26
26
  end
@@ -1,14 +1,16 @@
1
1
 
2
2
  ###
3
- # Convenience module for extending hash types (singletons and instances) with persistence capabilities.
3
+ # Convenience module for extending hash types (singletons and instances)
4
+ # with persistence capabilities.
4
5
  #
5
6
  module ::Persistence::Object::Complex::Hash
6
7
 
7
- extend ModuleCluster::Define::ClusterCascades
8
+ extend ::Module::Cluster
8
9
 
9
10
  include ::Persistence::Object::Complex
10
-
11
11
  include ::Persistence::Object::Complex::Hash::ObjectInstance
12
- include_or_extend_cascades_prepend_extends ::Persistence::Object::Complex::Hash::ClassInstance
12
+
13
+ cascade = cluster( :persistence ).before_include_or_extend.cascade
14
+ cascade.extend( ::Persistence::Object::Complex::Hash::ClassInstance )
13
15
 
14
16
  end
@@ -10,7 +10,7 @@ module ::Persistence::Object::Complex::Hash::ClassInstance
10
10
 
11
11
  def persist( *args )
12
12
 
13
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
13
+ index, key, no_key = parse_class_args_for_index_value_no_value( args, true )
14
14
 
15
15
  if index
16
16
  global_id = index.get_object_id( key )
@@ -10,7 +10,7 @@ module ::Persistence::Object::Complex::Hash::ObjectInstance
10
10
 
11
11
  def persist( *args )
12
12
 
13
- index, key, no_key = parse_args_for_index_value_no_value( args, true )
13
+ index, key, no_key = parse_object_args_for_index_value_no_value( args, true )
14
14
 
15
15
  if index
16
16
  global_id = index.get_object_id( key )
@@ -118,7 +118,7 @@ module ::Persistence::Object::Complex::ObjectInstance
118
118
  #
119
119
  def index_attributes
120
120
 
121
- attribute_indexes.each do |this_attribute_name, this_attribute_index|
121
+ self.class.attribute_indexes.each do |this_attribute_name, this_attribute_index|
122
122
  this_attribute_index.index_object( self )
123
123
  end
124
124
 
@@ -132,7 +132,7 @@ module ::Persistence::Object::Complex::ObjectInstance
132
132
 
133
133
  def persist( *args )
134
134
 
135
- index_instance, key, no_key = parse_args_for_index_value_no_value( args )
135
+ index_instance, key, no_key = parse_object_args_for_index_value_no_value( args )
136
136
 
137
137
  unless persistence_id
138
138
  if no_key
@@ -260,7 +260,7 @@ module ::Persistence::Object::Complex::ObjectInstance
260
260
  persistence_bucket.put_attribute!( self, attribute, value )
261
261
 
262
262
  if self.class.has_attribute_index?( attribute )
263
- attribute_indexes[ attribute ].index_object( self )
263
+ self.class.attribute_indexes[ attribute ].index_object( self )
264
264
  end
265
265
 
266
266
  # otherwise get from object
@@ -6,12 +6,13 @@
6
6
  #
7
7
  module ::Persistence::Object::Flat
8
8
 
9
- extend ModuleCluster::Define::ClusterCascades
9
+ extend ::Module::Cluster
10
10
 
11
11
  include ::Persistence::Object::ObjectInstance
12
- include_or_extend_cascades_prepend_extends ::Persistence::Object::ClassInstance
13
-
14
12
  include ::Persistence::Object::Flat::ObjectInstance
15
- include_or_extend_cascades_prepend_extends ::Persistence::Object::Flat::ClassInstance
16
-
13
+
14
+ cascade = cluster( :persistence ).before_include_or_extend.cascade
15
+ cascade.extend( ::Persistence::Object::ClassInstance,
16
+ ::Persistence::Object::Flat::ClassInstance )
17
+
17
18
  end
@@ -12,7 +12,7 @@ module ::Persistence::Object::Flat::ClassInstance
12
12
 
13
13
  persistence_value = nil
14
14
 
15
- index_instance, key, no_key = parse_args_for_index_value_no_value( args )
15
+ index_instance, key, no_key = parse_class_args_for_index_value_no_value( args )
16
16
 
17
17
  # if no key, open a cursor for a list
18
18
  if no_key
@@ -23,7 +23,7 @@ module ::Persistence::Object::Flat::ClassInstance
23
23
 
24
24
  global_id = index_instance ? index_instance.get_object_id( key ) : key
25
25
 
26
- persistence_value = instance_persistence_port.get_flat_object( global_id )
26
+ persistence_value = instance_persistence_bucket.get_flat_object( global_id )
27
27
 
28
28
  end
29
29
 
@@ -4,11 +4,12 @@
4
4
  #
5
5
  module ::Persistence::Object::Flat::File
6
6
 
7
- extend ModuleCluster::Define::ClusterCascades
7
+ extend ::Module::Cluster
8
8
 
9
9
  include ::Persistence::Object::Flat
10
-
11
10
  include ::Persistence::Object::Flat::File::ObjectInstance
12
- include_or_extend_cascades_prepend_extends ::Persistence::Object::Flat::File::ClassInstance
11
+
12
+ cascade = cluster( :persistence ).before_include_or_extend.cascade
13
+ cascade.extend( ::Persistence::Object::Flat::File::ClassInstance )
13
14
 
14
15
  end
@@ -12,14 +12,32 @@ module ::Persistence::Object::Flat::File::ClassInstance
12
12
 
13
13
  def persist( *args )
14
14
 
15
- persistence_value = super
15
+ persistence_value = nil
16
16
 
17
- if persists_file_paths_as_objects? and
18
- persistence_value.is_a?( ::Persistence::Object::Flat::File::Path )
17
+ index_instance, key, no_key = parse_class_args_for_index_value_no_value( args )
19
18
 
20
- persistence_value = File.open( persistence_value,
21
- persistence_value.mode || 'r' )
19
+ # if no key, open a cursor for a list
20
+ if no_key
22
21
 
22
+ persistence_value = ::Persistence::Cursor.new( instance_persistence_bucket, index_instance )
23
+
24
+ else
25
+
26
+ if global_id = index_instance ? index_instance.get_object_id( key ) : key
27
+
28
+ persistence_value_hash = instance_persistence_bucket.get_object_hash( global_id )
29
+
30
+ persistence_value = persistence_value_hash.first[ 1 ]
31
+
32
+ if persistence_value.is_a?( ::Persistence::Object::Flat::File::Path ) and
33
+ ! persists_file_paths_as_strings?
34
+
35
+ persistence_value = open( persistence_value, persistence_value.mode || 'r' )
36
+
37
+ end
38
+
39
+ end
40
+
23
41
  end
24
42
 
25
43
  return persistence_value
@@ -69,31 +87,6 @@ module ::Persistence::Object::Flat::File::ClassInstance
69
87
 
70
88
  end
71
89
 
72
- #####################################
73
- # persists_file_paths_as_objects? #
74
- #####################################
75
-
76
- ###
77
- # Query whether File paths should be persisted as objects (rather than by strings).
78
- # Lookup chain is: File instance, File class, Persistence::Port::Bucket instance, Persistence::Port instance,
79
- # Persistence singleton.
80
- #
81
- # @return [true,false] Whether files should be persisted as objects rather than as strings.
82
- #
83
- def persists_file_paths_as_objects?
84
-
85
- persists_file_paths_as_objects = nil
86
-
87
- persists_file_paths_as_objects = super
88
-
89
- if persists_file_paths_as_objects.nil?
90
- persists_file_paths_as_objects = instance_persistence_bucket.persists_file_paths_as_objects?
91
- end
92
-
93
- return persists_file_paths_as_objects
94
-
95
- end
96
-
97
90
  #####################################
98
91
  # persists_file_paths_as_strings? #
99
92
  #####################################