persistence 0.0.1.alpha → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +260 -17
- data/lib/namespaces.rb +55 -0
- data/lib/persistence.rb +38 -3
- data/lib/persistence/adapter/abstract.rb +22 -0
- data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
- data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
- data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
- data/lib/persistence/adapter/mock.rb +9 -0
- data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
- data/lib/persistence/adapter/mock/bucket.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
- data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
- data/lib/persistence/adapter/mock/cursor.rb +9 -0
- data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
- data/lib/persistence/cursor.rb +11 -0
- data/lib/persistence/cursor/atomic.rb +110 -0
- data/lib/persistence/cursor/cursor_interface.rb +337 -0
- data/lib/persistence/exception/block_required.rb +7 -0
- data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
- data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
- data/lib/persistence/exception/explicit_index_required.rb +7 -0
- data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
- data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
- data/lib/persistence/exception/key_value_required.rb +7 -0
- data/lib/persistence/exception/no_port_enabled.rb +7 -0
- data/lib/persistence/object.rb +21 -0
- data/lib/persistence/object/autodetermine.rb +74 -0
- data/lib/persistence/object/class_instance.rb +1884 -0
- data/lib/persistence/object/complex.rb +17 -0
- data/lib/persistence/object/complex/array.rb +14 -0
- data/lib/persistence/object/complex/array/class_instance.rb +37 -0
- data/lib/persistence/object/complex/array/object_instance.rb +54 -0
- data/lib/persistence/object/complex/attributes.rb +1808 -0
- data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
- data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
- data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
- data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
- data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
- data/lib/persistence/object/complex/class_instance.rb +267 -0
- data/lib/persistence/object/complex/complex_object.rb +111 -0
- data/lib/persistence/object/complex/hash.rb +14 -0
- data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
- data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
- data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
- data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
- data/lib/persistence/object/complex/object_instance.rb +469 -0
- data/lib/persistence/object/flat.rb +17 -0
- data/lib/persistence/object/flat/class_instance.rb +34 -0
- data/lib/persistence/object/flat/file.rb +14 -0
- data/lib/persistence/object/flat/file/class_instance.rb +122 -0
- data/lib/persistence/object/flat/file/contents.rb +7 -0
- data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
- data/lib/persistence/object/flat/file/object_instance.rb +116 -0
- data/lib/persistence/object/flat/file/path.rb +9 -0
- data/lib/persistence/object/flat/object_instance.rb +24 -0
- data/lib/persistence/object/index.rb +479 -0
- data/lib/persistence/object/index/block_index.rb +10 -0
- data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
- data/lib/persistence/object/index/explicit_index.rb +10 -0
- data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
- data/lib/persistence/object/index_hash.rb +40 -0
- data/lib/persistence/object/object_instance.rb +322 -0
- data/lib/persistence/object/parse_persistence_args.rb +145 -0
- data/lib/persistence/port.rb +9 -0
- data/lib/persistence/port/bucket.rb +9 -0
- data/lib/persistence/port/bucket/bucket_index.rb +9 -0
- data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
- data/lib/persistence/port/controller.rb +263 -0
- data/lib/persistence/port/port_interface.rb +417 -0
- data/lib/requires.rb +146 -0
- data/spec/Integration_spec.rb +53 -0
- data/spec/Persistence_spec.rb +175 -0
- data/spec/example_objects.rb +6 -0
- data/spec/example_objects/complex_object.rb +7 -0
- data/spec/example_objects/complex_object/array_object.rb +7 -0
- data/spec/example_objects/complex_object/hash_object.rb +7 -0
- data/spec/example_objects/flat_object.rb +7 -0
- data/spec/example_objects/flat_object/file_object.rb +7 -0
- data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
- data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
- data/spec/persistence/adapter/mock_helpers.rb +27 -0
- data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
- data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
- data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
- data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
- data/spec/persistence/adapter/mock_spec.rb +211 -0
- data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
- data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
- data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
- data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
- data/spec/persistence/cursor/atomic_spec.rb +86 -0
- data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
- data/spec/persistence/cursor_spec.rb +128 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
- data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
- data/spec/persistence/object/complex/complex_spec.rb +922 -0
- data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
- data/spec/persistence/object/flat/bignum_spec.rb +33 -0
- data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
- data/spec/persistence/object/flat/class_spec.rb +38 -0
- data/spec/persistence/object/flat/complex_spec.rb +36 -0
- data/spec/persistence/object/flat/false_class_spec.rb +34 -0
- data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
- data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
- data/spec/persistence/object/flat/file_spec.rb +64 -0
- data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
- data/spec/persistence/object/flat/float_spec.rb +32 -0
- data/spec/persistence/object/flat/indexing_spec.rb +38 -0
- data/spec/persistence/object/flat/rational_spec.rb +33 -0
- data/spec/persistence/object/flat/regexp_spec.rb +32 -0
- data/spec/persistence/object/flat/string_spec.rb +34 -0
- data/spec/persistence/object/flat/symbol_spec.rb +32 -0
- data/spec/persistence/object/flat/true_class_spec.rb +32 -0
- data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
- data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
- data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
- data/spec/persistence/object_spec.rb +310 -0
- data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
- data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
- data/spec/persistence/port/bucket_spec.rb +20 -0
- data/spec/persistence/port/controller_spec.rb +60 -0
- data/spec/persistence/port/port_interface_spec.rb +105 -0
- metadata +178 -21
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE +0 -22
- data/Rakefile +0 -2
- data/lib/persistence/version.rb +0 -3
- data/persistence.gemspec +0 -17
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Object::Flat::File do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a file object to a persistence port and get it back" do
|
15
|
+
class ::Persistence::Object::Flat::File::FileMock < File
|
16
|
+
include ::Persistence::Object::Flat::File
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
class ::Persistence::Object::Flat::File::Contents
|
20
|
+
include ::Persistence::Object::Flat
|
21
|
+
explicit_index :explicit_index
|
22
|
+
end
|
23
|
+
class ::Persistence::Object::Flat::File::Path
|
24
|
+
include ::Persistence::Object::Flat
|
25
|
+
explicit_index :explicit_index
|
26
|
+
end
|
27
|
+
file_object = ::Persistence::Object::Flat::File::FileMock.open( __FILE__, 'r' )
|
28
|
+
file_object.persistence_port.persist_files_by_path!
|
29
|
+
file_object.persistence_port.persist_file_paths_as_strings!
|
30
|
+
file_object.persist!
|
31
|
+
|
32
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( file_object.persistence_id )
|
33
|
+
persisted_file.should == file_object.path
|
34
|
+
file_object.persistence_port.persist_file_paths_as_objects!
|
35
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( file_object.persistence_id )
|
36
|
+
persisted_file.path.should == file_object.path
|
37
|
+
|
38
|
+
file_object.persistence_port.persists_files_by_content!
|
39
|
+
file_object.persist!
|
40
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( file_object.persistence_id )
|
41
|
+
persisted_file.should == file_object.readlines.join
|
42
|
+
file_object.cease!
|
43
|
+
::Persistence::Object::Flat::File::FileMock.persist( file_object.persistence_id ).should == nil
|
44
|
+
|
45
|
+
file_object.persistence_port.persist_files_by_path!
|
46
|
+
file_object.persistence_port.persist_file_paths_as_strings!
|
47
|
+
file_object.persist!( :explicit_index => __FILE__ )
|
48
|
+
|
49
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( :explicit_index => __FILE__ )
|
50
|
+
persisted_file.should == file_object.path
|
51
|
+
file_object.persistence_port.persist_file_paths_as_objects!
|
52
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( :explicit_index => __FILE__ )
|
53
|
+
persisted_file.path.should == file_object.path
|
54
|
+
|
55
|
+
file_object.persistence_port.persists_files_by_content!
|
56
|
+
file_object.persist!( :explicit_index => __FILE__ )
|
57
|
+
persisted_file = ::Persistence::Object::Flat::File::FileMock.persist( :explicit_index => __FILE__ )
|
58
|
+
persisted_file.should == file_object.readlines.join
|
59
|
+
::Persistence::Object::Flat::File::FileMock.cease!( :explicit_index => __FILE__ )
|
60
|
+
::Persistence::Object::Flat::File::FileMock.persist( :explicit_index => __FILE__ ).should == nil
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe Fixnum do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a fixnum number object to a persistence port and get it back" do
|
15
|
+
class Fixnum
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
fixnum_object = 420
|
20
|
+
fixnum_object.persist!
|
21
|
+
Fixnum.persist( fixnum_object.persistence_id ).should == fixnum_object
|
22
|
+
fixnum_object.cease!
|
23
|
+
Fixnum.persist( fixnum_object.persistence_id ).should == nil
|
24
|
+
|
25
|
+
storage_key = 12
|
26
|
+
fixnum_object.persist!( :explicit_index, storage_key )
|
27
|
+
Fixnum.persist( :explicit_index, storage_key ).should == fixnum_object
|
28
|
+
Fixnum.cease!( :explicit_index, storage_key )
|
29
|
+
Fixnum.persist( :explicit_index, storage_key ).should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe Float do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a float number object to a persistence port and get it back" do
|
15
|
+
class Float
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
float_object = 42.020
|
20
|
+
float_object.persist!
|
21
|
+
Float.persist( float_object.persistence_id ).should == float_object
|
22
|
+
float_object.cease!
|
23
|
+
Float.persist( float_object.persistence_id ).should == nil
|
24
|
+
|
25
|
+
storage_key = 37.0012
|
26
|
+
float_object.persist!( :explicit_index, storage_key )
|
27
|
+
Float.persist( :explicit_index, storage_key ).should == float_object
|
28
|
+
Float.cease!( :explicit_index, storage_key )
|
29
|
+
Float.persist( :explicit_index, storage_key ).should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Object::Flat do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
#############
|
15
|
+
# persist #
|
16
|
+
#############
|
17
|
+
|
18
|
+
it 'can persist a flat object and test whether it has been persisted' do
|
19
|
+
class ::Persistence::Object::Flat::Mock < ::String
|
20
|
+
include ::Persistence::Object::Flat
|
21
|
+
explicit_index :explicit_index
|
22
|
+
block_index :first_letter do
|
23
|
+
chars.first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
instance = ::Persistence::Object::Flat::Mock.new
|
27
|
+
instance.persist!
|
28
|
+
instance.persistence_id.should_not == nil
|
29
|
+
::Persistence::Object::Flat::Mock.persisted?( instance.persistence_id ).should == true
|
30
|
+
::Persistence::Object::Flat::Mock.persist( instance.persistence_id ).should == instance
|
31
|
+
instance_two = ::Persistence::Object::Flat::Mock.new( 'test' )
|
32
|
+
instance_two.persist!( :explicit_index => :some_value )
|
33
|
+
instance_two.persistence_id.should_not == nil
|
34
|
+
::Persistence::Object::Flat::Mock.persist( :explicit_index, :some_value ).should == instance_two
|
35
|
+
::Persistence::Object::Flat::Mock.persist( :first_letter => 't' ).should == instance_two
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe Rational do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a rational number object to a persistence port and get it back" do
|
15
|
+
class Rational
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
rational_object = Rational( 42, 37 )
|
20
|
+
rational_object.persist!
|
21
|
+
Rational.persist( rational_object.persistence_id ).should == rational_object
|
22
|
+
rational_object.cease!
|
23
|
+
Rational.persist( rational_object.persistence_id ).should == nil
|
24
|
+
|
25
|
+
rational_object = Rational( 42, 37 )
|
26
|
+
storage_key = Rational( 42, 420 )
|
27
|
+
rational_object.persist!( :explicit_index, storage_key )
|
28
|
+
Rational.persist( :explicit_index, storage_key ).should == rational_object
|
29
|
+
Rational.cease!( :explicit_index, storage_key )
|
30
|
+
Rational.persist( :explicit_index, storage_key ).should == nil
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Object::Flat do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a regexp object to a persistence port and get it back" do
|
15
|
+
class ::Persistence::Object::Flat::RegexpMock < Regexp
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
regexp_object = ::Persistence::Object::Flat::RegexpMock.new( /some_regexp_([A-Za-z])/ )
|
20
|
+
regexp_object.persist!
|
21
|
+
::Persistence::Object::Flat::RegexpMock.persist( regexp_object.persistence_id ).should == regexp_object
|
22
|
+
regexp_object.cease!
|
23
|
+
::Persistence::Object::Flat::RegexpMock.persist( regexp_object.persistence_id ).should == nil
|
24
|
+
|
25
|
+
storage_key = /regexp_storage_key/
|
26
|
+
regexp_object.persist!( :explicit_index, storage_key )
|
27
|
+
::Persistence::Object::Flat::RegexpMock.persist( :explicit_index, storage_key ).should == regexp_object
|
28
|
+
::Persistence::Object::Flat::RegexpMock.cease!( :explicit_index, storage_key )
|
29
|
+
::Persistence::Object::Flat::RegexpMock.persist( :explicit_index, storage_key ).should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Object::Flat do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a string object to a persistence port and get it back" do
|
15
|
+
class ::Persistence::Object::Flat::StringMock < String
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
string_object = ::Persistence::Object::Flat::StringMock.new( "some string" )
|
20
|
+
string_object.persist!
|
21
|
+
string_object.persistence_id.should_not == nil
|
22
|
+
::Persistence::Object::Flat::StringMock.persist( string_object.persistence_id ).should == string_object
|
23
|
+
string_object.cease!
|
24
|
+
::Persistence::Object::Flat::StringMock.persist( string_object.persistence_id ).should == nil
|
25
|
+
|
26
|
+
string_object = Persistence::Object::Flat::StringMock.new( "some string" )
|
27
|
+
storage_key = "string storage key"
|
28
|
+
string_object.persist!( :explicit_index, storage_key )
|
29
|
+
Persistence::Object::Flat::StringMock.persist( :explicit_index, storage_key ).should == string_object
|
30
|
+
Persistence::Object::Flat::StringMock.cease!( :explicit_index, storage_key )
|
31
|
+
Persistence::Object::Flat::StringMock.persist( :explicit_index, storage_key ).should == nil
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe Symbol do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a symbol object to a persistence port and get it back" do
|
15
|
+
class Symbol
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
symbol_object = :symbol
|
20
|
+
storage_key = :symbol_storage_key
|
21
|
+
symbol_object.persist!( :explicit_index, storage_key )
|
22
|
+
Symbol.persist( :explicit_index, storage_key ).should == symbol_object
|
23
|
+
symbol_object.cease!
|
24
|
+
Symbol.persist( :explicit_index, storage_key ).should == nil
|
25
|
+
|
26
|
+
symbol_object.persist!
|
27
|
+
Symbol.persist( symbol_object.persistence_id ).should == symbol_object
|
28
|
+
symbol_object.cease!
|
29
|
+
Symbol.persist( symbol_object.persistence_id ).should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe TrueClass do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
::Persistence.disable_port( :mock )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can put a true object to a persistence port and get it back" do
|
15
|
+
class TrueClass
|
16
|
+
include ::Persistence::Object::Flat
|
17
|
+
explicit_index :explicit_index
|
18
|
+
end
|
19
|
+
true_object = true
|
20
|
+
true_object.persist!
|
21
|
+
TrueClass.persist( true_object.persistence_id ).should == true_object
|
22
|
+
true_object.cease!
|
23
|
+
TrueClass.persist( true_object.persistence_id ).should == nil
|
24
|
+
|
25
|
+
storage_key = false
|
26
|
+
true_object.persist!( :explicit_index, storage_key )
|
27
|
+
TrueClass.persist( :explicit_index, storage_key ).should == true_object
|
28
|
+
true_object.cease!
|
29
|
+
TrueClass.persist( :explicit_index, storage_key ).should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Object::Index::BlockIndex do
|
5
|
+
|
6
|
+
#################################
|
7
|
+
# block_index #
|
8
|
+
# block_index_with_duplicates #
|
9
|
+
# has_block_index? #
|
10
|
+
# index #
|
11
|
+
#################################
|
12
|
+
|
13
|
+
it 'can declare an arbitrary key/value index on an object' do
|
14
|
+
class ::Persistence::Object::Index::BlockIndex::Mock
|
15
|
+
|
16
|
+
include ::Persistence::Object::Complex
|
17
|
+
|
18
|
+
block_index :block_index do |key, value|
|
19
|
+
return value
|
20
|
+
end
|
21
|
+
|
22
|
+
block_index_with_duplicates :block_index_with_duplicates do |key, value|
|
23
|
+
return value
|
24
|
+
end
|
25
|
+
|
26
|
+
has_block_index?( :block_index ).should == true
|
27
|
+
has_index?( :block_index ).should == true
|
28
|
+
has_block_index?( :block_index_with_duplicates ).should == true
|
29
|
+
has_index?( :block_index_with_duplicates ).should == true
|
30
|
+
index( :block_index ).is_a?( ::Persistence::Object::Index ).should == true
|
31
|
+
index( :block_index_with_duplicates ).is_a?( ::Persistence::Object::Index ).should == true
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
##################
|
37
|
+
# index_object #
|
38
|
+
##################
|
39
|
+
|
40
|
+
it 'can index an object by passing it to a block' do
|
41
|
+
# we want this test without port enabled to start
|
42
|
+
::Persistence.disable_port( :mock )
|
43
|
+
|
44
|
+
::Persistence::Object::Index::BlockIndex::IndexExistingObjects = ::Module.new
|
45
|
+
rspec = self
|
46
|
+
::Persistence::Object::Index::BlockIndex::IndexExistingObjects.module_eval do
|
47
|
+
|
48
|
+
class IndexMock
|
49
|
+
include ::Persistence::Object::Complex
|
50
|
+
attr_accessor :some_value
|
51
|
+
end
|
52
|
+
|
53
|
+
object = IndexMock.new
|
54
|
+
|
55
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
56
|
+
|
57
|
+
indexing_proc = Proc.new do |object|
|
58
|
+
object.some_value
|
59
|
+
end
|
60
|
+
|
61
|
+
index_instance = ::Persistence::Object::Index::BlockIndex.new( :block_index, object.persistence_bucket, false, & indexing_proc )
|
62
|
+
|
63
|
+
# test keys required for block with no returns
|
64
|
+
index_instance.requires_keys = true
|
65
|
+
Proc.new { index_instance.index_object( object ) }.should rspec.raise_error
|
66
|
+
# test keys not required for block with no returns
|
67
|
+
index_instance.requires_keys = false
|
68
|
+
Proc.new { index_instance.index_object( object ) }.should_not rspec.raise_error
|
69
|
+
|
70
|
+
# now to test indexing we want to require keys be generated
|
71
|
+
index_instance.requires_keys = true
|
72
|
+
|
73
|
+
object.some_value = :some_key
|
74
|
+
object.persist!
|
75
|
+
index_instance.index_object( object )
|
76
|
+
index_instance.persisted?( :some_key ).should == true
|
77
|
+
|
78
|
+
::Persistence.disable_port( :mock )
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
############################
|
84
|
+
# index_existing_objects #
|
85
|
+
############################
|
86
|
+
|
87
|
+
it 'can index an object by passing it to a block' do
|
88
|
+
module ::Persistence::Object::Index::BlockIndex::IndexExistingObjects
|
89
|
+
|
90
|
+
class ObjectInstance
|
91
|
+
include ::Persistence::Object::Complex
|
92
|
+
attr_accessor :some_value
|
93
|
+
end
|
94
|
+
|
95
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
96
|
+
|
97
|
+
object = ObjectInstance.new
|
98
|
+
|
99
|
+
object.persist!
|
100
|
+
|
101
|
+
ObjectInstance.persist( object.persistence_id ).should == object
|
102
|
+
|
103
|
+
indexing_proc = Proc.new do |object|
|
104
|
+
:some_key
|
105
|
+
end
|
106
|
+
|
107
|
+
index_instance = ::Persistence::Object::Index::BlockIndex.new( :other_block_index, object.persistence_bucket, false, & indexing_proc )
|
108
|
+
|
109
|
+
index_instance.persisted?( :some_key ).should == false
|
110
|
+
|
111
|
+
index_instance.index_existing_objects
|
112
|
+
index_instance.persisted?( :some_key ).should == true
|
113
|
+
|
114
|
+
::Persistence.disable_port( :mock )
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|