persistence 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/persistence.rb +0 -1
- data/lib/persistence/adapter/abstract.rb +1 -1
- data/lib/persistence/adapter/abstract/enable_disable.rb +1 -1
- data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +1 -1
- data/lib/persistence/adapter/abstract/primary_key/simple.rb +1 -1
- data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +1 -1
- data/lib/persistence/cursor/atomic.rb +2 -2
- data/lib/persistence/object.rb +1 -1
- data/lib/persistence/object/autodetermine.rb +5 -4
- data/lib/persistence/object/class_instance.rb +12 -8
- data/lib/persistence/object/complex.rb +4 -4
- data/lib/persistence/object/complex/array.rb +6 -4
- data/lib/persistence/object/complex/array/class_instance.rb +1 -1
- data/lib/persistence/object/complex/array/object_instance.rb +1 -1
- data/lib/persistence/object/complex/attributes/attributes_array.rb +1 -1
- data/lib/persistence/object/complex/hash.rb +6 -4
- data/lib/persistence/object/complex/hash/class_instance.rb +1 -1
- data/lib/persistence/object/complex/hash/object_instance.rb +1 -1
- data/lib/persistence/object/complex/object_instance.rb +3 -3
- data/lib/persistence/object/flat.rb +6 -5
- data/lib/persistence/object/flat/class_instance.rb +2 -2
- data/lib/persistence/object/flat/file.rb +4 -3
- data/lib/persistence/object/flat/file/class_instance.rb +23 -30
- data/lib/persistence/object/flat/file/file_persistence.rb +4 -53
- data/lib/persistence/object/flat/file/object_instance.rb +21 -42
- data/lib/persistence/object/index.rb +0 -1
- data/lib/persistence/object/index_hash.rb +1 -1
- data/lib/persistence/object/object_instance.rb +11 -11
- data/lib/persistence/object/parse_persistence_args.rb +2 -108
- data/lib/persistence/object/parse_persistence_args/class_instance.rb +124 -0
- data/lib/persistence/object/parse_persistence_args/object_instance.rb +124 -0
- data/lib/persistence/port/bucket/bucket_interface.rb +0 -18
- data/lib/persistence/port/port_interface.rb +1 -19
- data/lib/requires.rb +10 -9
- data/spec/persistence/object/complex/attributes_spec.rb +1 -140
- data/spec/persistence/object/flat/bignum_spec.rb +12 -4
- data/spec/persistence/object/flat/class_spec.rb +9 -4
- data/spec/persistence/object/flat/file/class_instance_spec.rb +0 -1
- data/spec/persistence/object/flat/file_spec.rb +6 -9
- data/spec/persistence/object/indexes/block_index_spec.rb +1 -1
- data/spec/persistence/object/parse_persistence_args/class_instance_spec.rb +61 -0
- data/spec/persistence/object/parse_persistence_args/object_instance_spec.rb +63 -0
- data/spec/persistence/object_spec.rb +48 -82
- data/spec/persistence/port/bucket/index/bucket_index_spec.rb +1 -0
- data/spec/{Persistence_spec.rb → persistence_spec.rb} +0 -0
- metadata +8 -5
- data/spec/persistence/object/parse_persistence_args_spec.rb +0 -65
data/lib/persistence.rb
CHANGED
@@ -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
|
data/lib/persistence/object.rb
CHANGED
@@ -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
|
17
|
+
persistence_object_module.extend( ::Module::Cluster )
|
17
18
|
|
18
|
-
persistence_object_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.
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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
|
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
|
-
|
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)
|
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
|
8
|
+
extend ::Module::Cluster
|
8
9
|
|
9
10
|
include ::Persistence::Object::Complex
|
10
|
-
|
11
11
|
include ::Persistence::Object::Complex::Array::ObjectInstance
|
12
|
-
|
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 =
|
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 =
|
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 )
|
@@ -1,14 +1,16 @@
|
|
1
1
|
|
2
2
|
###
|
3
|
-
# Convenience module for extending hash types (singletons and instances)
|
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
|
8
|
+
extend ::Module::Cluster
|
8
9
|
|
9
10
|
include ::Persistence::Object::Complex
|
10
|
-
|
11
11
|
include ::Persistence::Object::Complex::Hash::ObjectInstance
|
12
|
-
|
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 =
|
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 =
|
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 =
|
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
|
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
|
-
|
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 =
|
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 =
|
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
|
7
|
+
extend ::Module::Cluster
|
8
8
|
|
9
9
|
include ::Persistence::Object::Flat
|
10
|
-
|
11
10
|
include ::Persistence::Object::Flat::File::ObjectInstance
|
12
|
-
|
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 =
|
15
|
+
persistence_value = nil
|
16
16
|
|
17
|
-
|
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
|
-
|
21
|
-
|
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
|
#####################################
|