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.
Files changed (138) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +260 -17
  3. data/lib/namespaces.rb +55 -0
  4. data/lib/persistence.rb +38 -3
  5. data/lib/persistence/adapter/abstract.rb +22 -0
  6. data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
  7. data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
  8. data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
  9. data/lib/persistence/adapter/mock.rb +9 -0
  10. data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
  11. data/lib/persistence/adapter/mock/bucket.rb +9 -0
  12. data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
  13. data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
  14. data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
  15. data/lib/persistence/adapter/mock/cursor.rb +9 -0
  16. data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
  17. data/lib/persistence/cursor.rb +11 -0
  18. data/lib/persistence/cursor/atomic.rb +110 -0
  19. data/lib/persistence/cursor/cursor_interface.rb +337 -0
  20. data/lib/persistence/exception/block_required.rb +7 -0
  21. data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
  22. data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
  23. data/lib/persistence/exception/explicit_index_required.rb +7 -0
  24. data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
  25. data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
  26. data/lib/persistence/exception/key_value_required.rb +7 -0
  27. data/lib/persistence/exception/no_port_enabled.rb +7 -0
  28. data/lib/persistence/object.rb +21 -0
  29. data/lib/persistence/object/autodetermine.rb +74 -0
  30. data/lib/persistence/object/class_instance.rb +1884 -0
  31. data/lib/persistence/object/complex.rb +17 -0
  32. data/lib/persistence/object/complex/array.rb +14 -0
  33. data/lib/persistence/object/complex/array/class_instance.rb +37 -0
  34. data/lib/persistence/object/complex/array/object_instance.rb +54 -0
  35. data/lib/persistence/object/complex/attributes.rb +1808 -0
  36. data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
  37. data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
  38. data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
  39. data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
  40. data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
  41. data/lib/persistence/object/complex/class_instance.rb +267 -0
  42. data/lib/persistence/object/complex/complex_object.rb +111 -0
  43. data/lib/persistence/object/complex/hash.rb +14 -0
  44. data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
  45. data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
  46. data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
  47. data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
  48. data/lib/persistence/object/complex/object_instance.rb +469 -0
  49. data/lib/persistence/object/flat.rb +17 -0
  50. data/lib/persistence/object/flat/class_instance.rb +34 -0
  51. data/lib/persistence/object/flat/file.rb +14 -0
  52. data/lib/persistence/object/flat/file/class_instance.rb +122 -0
  53. data/lib/persistence/object/flat/file/contents.rb +7 -0
  54. data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
  55. data/lib/persistence/object/flat/file/object_instance.rb +116 -0
  56. data/lib/persistence/object/flat/file/path.rb +9 -0
  57. data/lib/persistence/object/flat/object_instance.rb +24 -0
  58. data/lib/persistence/object/index.rb +479 -0
  59. data/lib/persistence/object/index/block_index.rb +10 -0
  60. data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
  61. data/lib/persistence/object/index/explicit_index.rb +10 -0
  62. data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
  63. data/lib/persistence/object/index_hash.rb +40 -0
  64. data/lib/persistence/object/object_instance.rb +322 -0
  65. data/lib/persistence/object/parse_persistence_args.rb +145 -0
  66. data/lib/persistence/port.rb +9 -0
  67. data/lib/persistence/port/bucket.rb +9 -0
  68. data/lib/persistence/port/bucket/bucket_index.rb +9 -0
  69. data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
  70. data/lib/persistence/port/controller.rb +263 -0
  71. data/lib/persistence/port/port_interface.rb +417 -0
  72. data/lib/requires.rb +146 -0
  73. data/spec/Integration_spec.rb +53 -0
  74. data/spec/Persistence_spec.rb +175 -0
  75. data/spec/example_objects.rb +6 -0
  76. data/spec/example_objects/complex_object.rb +7 -0
  77. data/spec/example_objects/complex_object/array_object.rb +7 -0
  78. data/spec/example_objects/complex_object/hash_object.rb +7 -0
  79. data/spec/example_objects/flat_object.rb +7 -0
  80. data/spec/example_objects/flat_object/file_object.rb +7 -0
  81. data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
  82. data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
  83. data/spec/persistence/adapter/mock_helpers.rb +27 -0
  84. data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
  85. data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
  86. data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
  87. data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
  88. data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
  89. data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
  90. data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
  91. data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
  92. data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
  93. data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
  94. data/spec/persistence/adapter/mock_spec.rb +211 -0
  95. data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
  96. data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
  97. data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
  98. data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
  99. data/spec/persistence/cursor/atomic_spec.rb +86 -0
  100. data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
  101. data/spec/persistence/cursor_spec.rb +128 -0
  102. data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
  103. data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
  104. data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
  105. data/spec/persistence/object/complex/complex_spec.rb +922 -0
  106. data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
  107. data/spec/persistence/object/flat/bignum_spec.rb +33 -0
  108. data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
  109. data/spec/persistence/object/flat/class_spec.rb +38 -0
  110. data/spec/persistence/object/flat/complex_spec.rb +36 -0
  111. data/spec/persistence/object/flat/false_class_spec.rb +34 -0
  112. data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
  113. data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
  114. data/spec/persistence/object/flat/file_spec.rb +64 -0
  115. data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
  116. data/spec/persistence/object/flat/float_spec.rb +32 -0
  117. data/spec/persistence/object/flat/indexing_spec.rb +38 -0
  118. data/spec/persistence/object/flat/rational_spec.rb +33 -0
  119. data/spec/persistence/object/flat/regexp_spec.rb +32 -0
  120. data/spec/persistence/object/flat/string_spec.rb +34 -0
  121. data/spec/persistence/object/flat/symbol_spec.rb +32 -0
  122. data/spec/persistence/object/flat/true_class_spec.rb +32 -0
  123. data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
  124. data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
  125. data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
  126. data/spec/persistence/object_spec.rb +310 -0
  127. data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
  128. data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
  129. data/spec/persistence/port/bucket_spec.rb +20 -0
  130. data/spec/persistence/port/controller_spec.rb +60 -0
  131. data/spec/persistence/port/port_interface_spec.rb +105 -0
  132. metadata +178 -21
  133. data/.gitignore +0 -17
  134. data/Gemfile +0 -4
  135. data/LICENSE +0 -22
  136. data/Rakefile +0 -2
  137. data/lib/persistence/version.rb +0 -3
  138. data/persistence.gemspec +0 -17
@@ -0,0 +1,76 @@
1
+
2
+ require_relative '../../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::Complex::Index::AttributeIndex do
5
+
6
+ ##################
7
+ # index_object #
8
+ ##################
9
+
10
+ it 'can index a specific attribute on an object' do
11
+
12
+ class ::Persistence::Object::Complex::Index::AttributeIndex::Mock
13
+ include ::Persistence::Object::Complex
14
+ attr_non_atomic_accessor :some_value
15
+ end
16
+
17
+ object = ::Persistence::Object::Complex::Index::AttributeIndex::Mock.new
18
+
19
+ bucket = object.persistence_bucket
20
+
21
+ bucket.index( :attribute_index ).should == nil
22
+
23
+ # before port
24
+ index_instance = ::Persistence::Object::Complex::Index::AttributeIndex.new( :attribute_index, bucket, false )
25
+ index_instance.attribute_name = :some_value
26
+ Proc.new { bucket.create_index( :attribute_index, true ) }.should raise_error
27
+ index_instance.permits_duplicates?.should == false
28
+ Proc.new { index_instance.adapter_index }.should raise_error
29
+ Proc.new { index_instance.index_object( object ) }.should raise_error
30
+ Proc.new { index_instance.persisted?( :any_key ) }.should raise_error
31
+ Proc.new { index_instance.get_object_id( :any_key ) }.should raise_error
32
+ Proc.new { index_instance.index_object_id( any_id = 0, :any_key ) }.should raise_error
33
+ Proc.new { index_instance.delete_keys_for_object_id!( any_id = 0 ) }.should raise_error
34
+
35
+ # after port
36
+ ::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
37
+
38
+ index_instance.adapter_index.should_not == nil
39
+
40
+ bucket.index( :other_attribute_index ).should == nil
41
+ index_instance_two = ::Persistence::Object::Complex::Index::AttributeIndex.new( :other_attribute_index, bucket, true )
42
+ index_instance_two.attribute_name = :some_value
43
+ index_instance_two.adapter_index.should_not == nil
44
+ index_instance_two.permits_duplicates?.should == true
45
+ index_instance_two_conflicting_settings = Proc.new { bucket.create_index( :other_attribute_index, false ) }.should raise_error
46
+
47
+ index_instance.persisted?( :any_key ).should == false
48
+ index_instance.get_object_id( :any_key ).should == nil
49
+
50
+ object.some_value = :some_key
51
+
52
+ # put object
53
+ object.persist!
54
+
55
+ # create arbitrary index value for object
56
+ index_instance.index_object( object )
57
+
58
+ # test retrieval of ID for index value
59
+ index_instance.persisted?( :some_key ).should == true
60
+ index_instance.get_object_id( :some_key ).should == object.persistence_id
61
+
62
+ # delete keys
63
+ index_instance.delete_keys_for_object_id!( object.persistence_id )
64
+ index_instance.get_object_id( :some_key ).should == nil
65
+
66
+ # delete object
67
+ index_instance.index_object( object )
68
+ index_instance.get_object_id( :some_key ).should == object.persistence_id
69
+ index_instance.delete_keys_for_object!( object )
70
+ index_instance.get_object_id( :some_key ).should == nil
71
+
72
+ ::Persistence.disable_port( :mock )
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,33 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe Bignum 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 bignum number object to a persistence port and get it back" do
15
+ class Bignum
16
+ include ::Persistence::Object::Flat
17
+ explicit_index :explicit_index
18
+ end
19
+ bignum_object = 10**20
20
+ bignum_object.persist!
21
+ Bignum.persist( bignum_object.persistence_id ).should == bignum_object
22
+ bignum_object.cease!
23
+ Bignum.persist( bignum_object.persistence_id ).should == nil
24
+
25
+ storage_key = 10**40
26
+ bignum_object.persist!( :explicit_index => storage_key )
27
+ Bignum.persist( :explicit_index => storage_key ).should == bignum_object
28
+ Bignum.cease!( :explicit_index => storage_key )
29
+ Bignum.persist( :explicit_index => storage_key ).should == nil
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,30 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::Flat::ClassInstance 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::ClassInstance::Mock
20
+ include ::Persistence::Object::Flat
21
+ self.instance_persistence_port = ::Persistence.port( :mock_port )
22
+ end
23
+ instance = ::Persistence::Object::Flat::ClassInstance::Mock.new
24
+ instance.persistence_port.put_object!( instance )
25
+ instance.persistence_id.nil?.should == false
26
+ ::Persistence::Object::Flat::ClassInstance::Mock.persisted?( 0 ).should == true
27
+ ::Persistence::Object::Flat::ClassInstance::Mock.persist( 0 ).should == instance
28
+ end
29
+
30
+ end
@@ -0,0 +1,38 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe Class 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 class object to a persistence port and get it back" do
15
+ class Class
16
+ include ::Persistence::Object::Flat
17
+ explicit_index :explicit_index
18
+ end
19
+
20
+ class_object = Object
21
+ class_object.persist!
22
+ Class.persist( class_object.persistence_id ).should == class_object
23
+ class_object.cease!
24
+ Class.persist( class_object.persistence_id ).should == nil
25
+ ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default ).remove_configuration( Class, :instance_persistence_port )
26
+ ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default ).remove_configuration( Class, :instance_persistence_bucket )
27
+
28
+ storage_key = String
29
+ class_object.persist!( :explicit_index, storage_key )
30
+ Class.persist( :explicit_index, storage_key ).should == class_object
31
+ Class.cease!( :explicit_index, storage_key )
32
+ Class.persist( :explicit_index, storage_key ).should == nil
33
+ ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default ).remove_configuration( Class, :instance_persistence_port )
34
+ ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default ).remove_configuration( Class, :instance_persistence_bucket )
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,36 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe Complex 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 complex number object to a persistence port and get it back" do
15
+ class Complex
16
+ include ::Persistence::Object::Flat
17
+ explicit_index :explicit_index
18
+ end
19
+
20
+ complex_object = Complex( 42, 1 )
21
+ storage_key = Complex( 37, 12 )
22
+ complex_object.persist!
23
+ Complex.persist( complex_object.persistence_id ).should == complex_object
24
+ complex_object.cease!
25
+ Complex.persist( complex_object.persistence_id ).should == nil
26
+
27
+ complex_object = Complex( 42, 1 )
28
+ storage_key = Complex( 37, 12 )
29
+ complex_object.persist!( :explicit_index, storage_key )
30
+ Complex.persist( :explicit_index, storage_key ).should == complex_object
31
+ Complex.cease!( :explicit_index, storage_key )
32
+ Complex.persist( :explicit_index, storage_key ).should == nil
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,34 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe FalseClass 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 false object to a persistence port and get it back" do
15
+ class FalseClass
16
+ include ::Persistence::Object::Flat
17
+ explicit_index :explicit_index
18
+ end
19
+ false_object = false
20
+ storage_key = true
21
+ false_object.persist!
22
+ FalseClass.persist( false_object.persistence_id ).should == false_object
23
+ false_object.cease!
24
+ FalseClass.persist( false_object.persistence_id ).should == nil
25
+
26
+ false_object = false
27
+ storage_key = true
28
+ false_object.persist!( :explicit_index, storage_key )
29
+ FalseClass.persist( :explicit_index, storage_key ).should == false_object
30
+ FalseClass.cease!( :explicit_index, storage_key )
31
+ FalseClass.persist( :explicit_index, storage_key ).should == nil
32
+ end
33
+
34
+ end
@@ -0,0 +1,54 @@
1
+
2
+ require_relative '../../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::Flat::File::ClassInstance 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::File::ClassInstance::FileMock < File
20
+ include ::Persistence::Object::Flat::File
21
+ end
22
+ class ::Persistence::Object::Flat::File::Contents
23
+ include ::Persistence::Object::Flat
24
+ end
25
+ class ::Persistence::Object::Flat::File::Path
26
+ include ::Persistence::Object::Flat
27
+ end
28
+
29
+ ::Persistence::Object::Flat::File::ClassInstance::FileMock.instance_persistence_port = :mock
30
+ instance = ::Persistence::Object::Flat::File::ClassInstance::FileMock.open( __FILE__, 'r' )
31
+
32
+ # by content
33
+ instance_to_persist = ::Persistence::Object::Flat::File::Contents.new( instance.readlines.join )
34
+ instance_to_persist.persistence_bucket = ::Persistence::Object::Flat::File::ClassInstance::FileMock.instance_persistence_bucket
35
+ instance_to_persist.persistence_port.put_object!( instance_to_persist )
36
+ instance_to_persist.persistence_id.should_not == nil
37
+
38
+ ::Persistence::Object::Flat::File::ClassInstance::FileMock.instance_persistence_port.persists_files_by_content!
39
+ persisted_file = ::Persistence::Object::Flat::File::ClassInstance::FileMock.persist( instance_to_persist.persistence_id )
40
+ persisted_file.should == instance_to_persist
41
+
42
+ # by path
43
+ instance_to_persist_two = ::Persistence::Object::Flat::File::Path.new( instance.path )
44
+ instance_to_persist_two.persistence_bucket = ::Persistence::Object::Flat::File::ClassInstance::FileMock.instance_persistence_bucket
45
+ instance_to_persist_two.persistence_port.put_object!( instance_to_persist_two )
46
+ instance_to_persist_two.persistence_id.should_not == nil
47
+
48
+ ::Persistence::Object::Flat::File::ClassInstance::FileMock.instance_persistence_port.persist_file_paths_as_objects!
49
+ persisted_file_two = ::Persistence::Object::Flat::File::ClassInstance::FileMock.persist( instance_to_persist_two.persistence_id )
50
+ persisted_file_two.is_a?( File ).should == true
51
+ persisted_file_two.path.should == instance_to_persist_two
52
+ end
53
+
54
+ end
@@ -0,0 +1,143 @@
1
+
2
+ require_relative '../../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::Flat::File::ObjectInstance 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::File::ObjectInstance::FileMock < File
20
+ include ::Persistence::Object::Flat::File
21
+ end
22
+ class ::Persistence::Object::Flat::File::Contents
23
+ include ::Persistence::Object::Flat
24
+ end
25
+ class ::Persistence::Object::Flat::File::Path
26
+ include ::Persistence::Object::Flat
27
+ end
28
+
29
+ ::Persistence::Object::Flat::File::ObjectInstance::FileMock.instance_persistence_port = :mock
30
+ instance = ::Persistence::Object::Flat::File::ObjectInstance::FileMock.open( __FILE__, 'r' )
31
+
32
+ # by content
33
+ instance.persists_files_by_content?.should == false
34
+ instance.persist_files_by_content!
35
+ instance.persists_files_by_content?.should == true
36
+ instance.persists_files_by_path?.should == false
37
+ instance.persist!
38
+ instance.persistence_id.should_not == nil
39
+ instance.persistence_port.get_flat_object( instance.persistence_id ).should == instance.readlines.join
40
+ instance.cease!
41
+
42
+ # by path
43
+ instance.persistence_id = nil
44
+ instance.persist_files_by_path!
45
+ instance.persist!
46
+ instance.persistence_id.should_not == nil
47
+ instance.persistence_port.get_flat_object( instance.persistence_id ).should == instance.path
48
+ end
49
+
50
+ ###############################
51
+ # persist_files_by_path #
52
+ # persists_files_by_content #
53
+ # persists_files_by_path? #
54
+ ###############################
55
+
56
+ it 'can persist files either by path or contents' do
57
+ module ::Persistence::Object::Flat::File::ObjectInstance::PersistFileByPathMock
58
+
59
+ class FileMock < ::File
60
+ include ::Persistence::Object::Flat::File
61
+ end
62
+
63
+ # Controller
64
+ ::Persistence.persists_files_by_path?.should == true
65
+ ::Persistence.persist_files_by_content!
66
+ ::Persistence.persists_files_by_path?.should == false
67
+ ::Persistence.persists_files_by_content?.should == true
68
+ ::Persistence.persist_files_by_path!
69
+ ::Persistence.persists_files_by_path?.should == true
70
+ ::Persistence.persists_files_by_content?.should == false
71
+
72
+ # Port
73
+ port_instance = FileMock.instance_persistence_port
74
+ port_instance.persists_files_by_path?.should == true
75
+ port_instance.persist_files_by_content!
76
+ port_instance.persists_files_by_path?.should == false
77
+ port_instance.persists_files_by_content?.should == true
78
+ port_instance.persist_files_by_path!
79
+ port_instance.persists_files_by_path?.should == true
80
+ port_instance.persists_files_by_content?.should == false
81
+ port_instance.persist_files_by_content!
82
+
83
+ # Bucket
84
+ bucket_instance = FileMock.instance_persistence_bucket
85
+ bucket_instance.persists_files_by_path?.should == false
86
+ port_instance.persist_files_by_path!
87
+ bucket_instance.persists_files_by_path?.should == true
88
+ bucket_instance.persists_files_by_content!
89
+ bucket_instance.persists_files_by_path?.should == false
90
+ port_instance.persist_files_by_path!
91
+ bucket_instance.persists_files_by_path?.should == false
92
+ bucket_instance.persist_files_by_path!
93
+ port_instance.persists_files_by_content!
94
+ bucket_instance.persists_files_by_path?.should == true
95
+ bucket_instance.persists_files_by_content!
96
+ port_instance.persist_files_by_path!
97
+
98
+ # Class
99
+ FileMock.class_eval do
100
+ persists_files_by_path?.should == false
101
+ bucket_instance.persist_files_by_path!
102
+ persists_files_by_path?.should == true
103
+ bucket_instance.persist_files_by_content!
104
+ persists_files_by_path?.should == false
105
+ port_instance.persist_files_by_path!
106
+ persists_files_by_path?.should == false
107
+ persist_files_by_path!
108
+ persists_files_by_path?.should == true
109
+ persists_files_by_content!
110
+ persists_files_by_path?.should == false
111
+ bucket_instance.persists_files_by_path?.should == false
112
+ port_instance.persists_files_by_path?.should == true
113
+ end
114
+
115
+ # Instance
116
+ FileMock.new( __FILE__ ).instance_eval do
117
+ persists_files_by_path?.should == false
118
+ self.class.persist_files_by_path!
119
+ persists_files_by_path?.should == true
120
+ bucket_instance.persist_files_by_content!
121
+ persists_files_by_path?.should == true
122
+ self.class.persist_files_by_path!
123
+ persists_files_by_path?.should == true
124
+ self.class.persists_files_by_content!
125
+ persists_files_by_path?.should == false
126
+ bucket_instance.persist_files_by_path!
127
+ persists_files_by_path?.should == false
128
+ port_instance.persist_files_by_path!
129
+ persists_files_by_path?.should == false
130
+ persist_files_by_path!
131
+ persists_files_by_path?.should == true
132
+ persists_files_by_content!
133
+ persists_files_by_path?.should == false
134
+ self.class.persists_files_by_path?.should == false
135
+ bucket_instance.persists_files_by_path?.should == true
136
+ port_instance.persists_files_by_path?.should == true
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+
143
+ end