simply_stored 0.3.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/CHANGELOG.md +38 -0
  2. data/README.md +45 -24
  3. data/lib/simply_stored/couch/association_property.rb +27 -0
  4. data/lib/simply_stored/couch/belongs_to.rb +5 -7
  5. data/lib/simply_stored/couch/finders.rb +5 -1
  6. data/lib/simply_stored/couch/has_and_belongs_to_many.rb +202 -0
  7. data/lib/simply_stored/couch/has_many.rb +6 -51
  8. data/lib/simply_stored/couch/has_one.rb +4 -29
  9. data/lib/simply_stored/couch/properties.rb +11 -0
  10. data/lib/simply_stored/couch.rb +38 -2
  11. data/lib/simply_stored/instance_methods.rb +68 -29
  12. data/lib/simply_stored.rb +3 -1
  13. data/test/{couchdb/couch_active_model_compatibility_test.rb → active_model_compatibility_test.rb} +2 -2
  14. data/test/{couchdb/couch_belongs_to_test.rb → belongs_to_test.rb} +13 -3
  15. data/test/{couchdb/couch_conflict_handling_test.rb → conflict_handling_test.rb} +3 -3
  16. data/test/{couchdb/couch_finder_test.rb → finder_test.rb} +8 -3
  17. data/test/fixtures/couch.rb +55 -0
  18. data/test/has_and_belongs_to_many_test.rb +639 -0
  19. data/test/{couchdb/couch_has_many_test.rb → has_many_test.rb} +13 -3
  20. data/test/{couchdb/couch_has_one_test.rb → has_one_test.rb} +13 -3
  21. data/test/{couchdb/couch_instance_lifecycle_test.rb → instance_lifecycle_test.rb} +3 -3
  22. data/test/{couchdb/couch_mass_assignment_protection_test.rb → mass_assignment_protection_test.rb} +3 -3
  23. data/test/{couchdb/couch_s3_test.rb → s3_test.rb} +3 -3
  24. data/test/{couchdb/couch_soft_deletable_test.rb → soft_deletable_test.rb} +3 -3
  25. data/test/test_helper.rb +1 -5
  26. data/test/{couchdb/couch_validations_test.rb → validations_test.rb} +3 -3
  27. data/test/{couchdb/custom_views_test.rb → views_test.rb} +3 -3
  28. metadata +36 -234
  29. data/lib/simply_stored/simpledb/associations.rb +0 -215
  30. data/lib/simply_stored/simpledb/attributes.rb +0 -173
  31. data/lib/simply_stored/simpledb/storag.rb +0 -85
  32. data/lib/simply_stored/simpledb/validations.rb +0 -88
  33. data/lib/simply_stored/simpledb.rb +0 -216
  34. data/test/fixtures/simpledb/item.rb +0 -11
  35. data/test/fixtures/simpledb/item_daddy.rb +0 -8
  36. data/test/fixtures/simpledb/log_item.rb +0 -3
  37. data/test/fixtures/simpledb/namespace_bar.rb +0 -5
  38. data/test/fixtures/simpledb/namespace_foo.rb +0 -7
  39. data/test/fixtures/simpledb/protected_item.rb +0 -3
  40. data/test/simply_stored_simpledb_test.rb +0 -1376
  41. data/test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb +0 -29
  42. data/test/vendor/dhaka-2.2.1/lib/dhaka/evaluator/evaluator.rb +0 -133
  43. data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/closure_hash.rb +0 -15
  44. data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar.rb +0 -240
  45. data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar_symbol.rb +0 -27
  46. data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/precedence.rb +0 -19
  47. data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/production.rb +0 -36
  48. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/accept_actions.rb +0 -36
  49. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/alphabet.rb +0 -21
  50. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/compiled_lexer.rb +0 -46
  51. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/dfa.rb +0 -121
  52. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexeme.rb +0 -32
  53. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer.rb +0 -70
  54. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer_run.rb +0 -78
  55. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_grammar.rb +0 -392
  56. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_parser.rb +0 -2010
  57. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_tokenizer.rb +0 -14
  58. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/specification.rb +0 -96
  59. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state.rb +0 -68
  60. data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state_machine.rb +0 -37
  61. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/action.rb +0 -55
  62. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/channel.rb +0 -58
  63. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/compiled_parser.rb +0 -51
  64. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/conflict.rb +0 -54
  65. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/item.rb +0 -42
  66. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_result.rb +0 -50
  67. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_tree.rb +0 -66
  68. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser.rb +0 -165
  69. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_methods.rb +0 -11
  70. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_run.rb +0 -39
  71. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_state.rb +0 -74
  72. data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/token.rb +0 -22
  73. data/test/vendor/dhaka-2.2.1/lib/dhaka/runtime.rb +0 -51
  74. data/test/vendor/dhaka-2.2.1/lib/dhaka/tokenizer/tokenizer.rb +0 -190
  75. data/test/vendor/dhaka-2.2.1/lib/dhaka.rb +0 -62
  76. data/test/vendor/dhaka-2.2.1/test/all_tests.rb +0 -5
  77. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator.rb +0 -64
  78. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator_test.rb +0 -43
  79. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar.rb +0 -41
  80. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar_test.rb +0 -9
  81. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_test_methods.rb +0 -9
  82. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer.rb +0 -39
  83. data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer_test.rb +0 -38
  84. data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_evaluator.rb +0 -43
  85. data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar.rb +0 -24
  86. data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar_test.rb +0 -30
  87. data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_lexer_specification.rb +0 -23
  88. data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_parser_test.rb +0 -33
  89. data/test/vendor/dhaka-2.2.1/test/brackets/bracket_grammar.rb +0 -23
  90. data/test/vendor/dhaka-2.2.1/test/brackets/bracket_tokenizer.rb +0 -22
  91. data/test/vendor/dhaka-2.2.1/test/brackets/brackets_test.rb +0 -28
  92. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver.rb +0 -46
  93. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver_test.rb +0 -276
  94. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator.rb +0 -284
  95. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator_test.rb +0 -38
  96. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_grammar.rb +0 -104
  97. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer.rb +0 -109
  98. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_specification.rb +0 -37
  99. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_test.rb +0 -58
  100. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser.rb +0 -879
  101. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser_test.rb +0 -55
  102. data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_test.rb +0 -170
  103. data/test/vendor/dhaka-2.2.1/test/core/another_lalr_but_not_slr_grammar.rb +0 -20
  104. data/test/vendor/dhaka-2.2.1/test/core/compiled_parser_test.rb +0 -44
  105. data/test/vendor/dhaka-2.2.1/test/core/dfa_test.rb +0 -170
  106. data/test/vendor/dhaka-2.2.1/test/core/evaluator_test.rb +0 -22
  107. data/test/vendor/dhaka-2.2.1/test/core/grammar_test.rb +0 -83
  108. data/test/vendor/dhaka-2.2.1/test/core/lalr_but_not_slr_grammar.rb +0 -19
  109. data/test/vendor/dhaka-2.2.1/test/core/lexer_test.rb +0 -139
  110. data/test/vendor/dhaka-2.2.1/test/core/malformed_grammar.rb +0 -7
  111. data/test/vendor/dhaka-2.2.1/test/core/malformed_grammar_test.rb +0 -8
  112. data/test/vendor/dhaka-2.2.1/test/core/nullable_grammar.rb +0 -21
  113. data/test/vendor/dhaka-2.2.1/test/core/parse_result_test.rb +0 -44
  114. data/test/vendor/dhaka-2.2.1/test/core/parser_state_test.rb +0 -24
  115. data/test/vendor/dhaka-2.2.1/test/core/parser_test.rb +0 -131
  116. data/test/vendor/dhaka-2.2.1/test/core/precedence_grammar.rb +0 -17
  117. data/test/vendor/dhaka-2.2.1/test/core/precedence_grammar_test.rb +0 -9
  118. data/test/vendor/dhaka-2.2.1/test/core/rr_conflict_grammar.rb +0 -21
  119. data/test/vendor/dhaka-2.2.1/test/core/simple_grammar.rb +0 -22
  120. data/test/vendor/dhaka-2.2.1/test/core/sr_conflict_grammar.rb +0 -16
  121. data/test/vendor/dhaka-2.2.1/test/dhaka_test_helper.rb +0 -17
  122. data/test/vendor/dhaka-2.2.1/test/fake_logger.rb +0 -17
  123. data/test/vendor/simplerdb-0.2/lib/simplerdb/client_exception.rb +0 -10
  124. data/test/vendor/simplerdb-0.2/lib/simplerdb/db.rb +0 -146
  125. data/test/vendor/simplerdb-0.2/lib/simplerdb/query_language.rb +0 -266
  126. data/test/vendor/simplerdb-0.2/lib/simplerdb/server.rb +0 -33
  127. data/test/vendor/simplerdb-0.2/lib/simplerdb/servlet.rb +0 -191
  128. data/test/vendor/simplerdb-0.2/lib/simplerdb.rb +0 -3
  129. data/test/vendor/simplerdb-0.2/test/functional_test.rb +0 -81
  130. data/test/vendor/simplerdb-0.2/test/query_evaluator_test.rb +0 -73
  131. data/test/vendor/simplerdb-0.2/test/query_parser_test.rb +0 -64
  132. data/test/vendor/simplerdb-0.2/test/simplerdb_test.rb +0 -80
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
- class CouchTest < Test::Unit::TestCase
4
+ class InstanceLifecycleTest < Test::Unit::TestCase
5
5
  context "A simply stored couch instance" do
6
6
  setup do
7
7
  CouchPotato::Config.database_name = 'simply_stored_test'
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
- class CouchMassAssignmentProtectionTest < Test::Unit::TestCase
4
+ class MassAssignmentProtectionTest < Test::Unit::TestCase
5
5
  context "attribute proctection against mass assignment" do
6
6
  setup do
7
7
  CouchPotato::Config.database_name = 'simply_stored_test'
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
- class CouchS3Test < Test::Unit::TestCase
4
+ class S3Test < Test::Unit::TestCase
5
5
  context "with s3 interaction" do
6
6
  setup do
7
7
  CouchPotato::Config.database_name = 'simply_stored_test'
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
- class CouchSoftDeletableTest < Test::Unit::TestCase
4
+ class SoftDeletableTest < Test::Unit::TestCase
5
5
  context "when using soft deletable" do
6
6
  setup do
7
7
  CouchPotato::Config.database_name = 'simply_stored_test'
data/test/test_helper.rb CHANGED
@@ -6,11 +6,7 @@ require 'active_support'
6
6
  require 'active_support/testing/assertions'
7
7
  $:.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
8
8
  puts File.expand_path(File.dirname(__FILE__) + "/lib")
9
- require 'simply_stored/couch'
10
- require 'simply_stored/simpledb'
11
-
12
- $:.<< File.expand_path(File.dirname(__FILE__) + "/vendor/simplerdb-0.2/lib")
13
- $:.<< File.expand_path(File.dirname(__FILE__) + "/vendor/dhaka-2.2.1/lib")
9
+ require 'simply_stored'
14
10
 
15
11
  class Test::Unit::TestCase
16
12
  include ActiveSupport::Testing::Assertions
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
- class CouchValidationsTest < Test::Unit::TestCase
4
+ class ValidationsTest < Test::Unit::TestCase
5
5
  context "with additional validations" do
6
6
  setup do
7
7
  CouchPotato::Config.database_name = 'simply_stored_test'
@@ -1,5 +1,5 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
3
3
 
4
4
  class CustomViewUser
5
5
  include SimplyStored::Couch
@@ -8,7 +8,7 @@ class CustomViewUser
8
8
  view :by_tags, :type => SimplyStored::Couch::Views::ArrayPropertyViewSpec, :key => :tags
9
9
  end
10
10
 
11
- class CustomViewsTest < Test::Unit::TestCase
11
+ class ViewsTest < Test::Unit::TestCase
12
12
 
13
13
  context "Custom couch views" do
14
14
  setup do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_stored
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 9
10
- version: 0.3.9
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mathias Meyer, Jonathan Weiss
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-28 00:00:00 +02:00
18
+ date: 2011-02-22 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: "0"
79
79
  type: :runtime
80
80
  version_requirements: *id004
81
- description: Convenience layer for CouchDB and SimpleDB. Requires CouchPotato and RightAWS library respectively.
81
+ description: Convenience layer for CouchDB on top of CouchPotato.
82
82
  email: info@peritor.com
83
83
  executables: []
84
84
 
@@ -94,136 +94,36 @@ files:
94
94
  - lib/simply_stored.rb
95
95
  - lib/simply_stored/class_methods_base.rb
96
96
  - lib/simply_stored/couch.rb
97
+ - lib/simply_stored/couch/association_property.rb
97
98
  - lib/simply_stored/couch/belongs_to.rb
98
99
  - lib/simply_stored/couch/ext/couch_potato.rb
99
100
  - lib/simply_stored/couch/find_by.rb
100
101
  - lib/simply_stored/couch/finders.rb
102
+ - lib/simply_stored/couch/has_and_belongs_to_many.rb
101
103
  - lib/simply_stored/couch/has_many.rb
102
104
  - lib/simply_stored/couch/has_one.rb
105
+ - lib/simply_stored/couch/properties.rb
103
106
  - lib/simply_stored/couch/validations.rb
104
107
  - lib/simply_stored/couch/views.rb
105
108
  - lib/simply_stored/couch/views/array_property_view_spec.rb
106
109
  - lib/simply_stored/instance_methods.rb
107
110
  - lib/simply_stored/rake.rb
108
- - lib/simply_stored/simpledb.rb
109
- - lib/simply_stored/simpledb/associations.rb
110
- - lib/simply_stored/simpledb/attributes.rb
111
- - lib/simply_stored/simpledb/storag.rb
112
- - lib/simply_stored/simpledb/validations.rb
113
111
  - lib/simply_stored/storage.rb
114
- - test/couchdb/couch_active_model_compatibility_test.rb
115
- - test/couchdb/couch_belongs_to_test.rb
116
- - test/couchdb/couch_conflict_handling_test.rb
117
- - test/couchdb/couch_finder_test.rb
118
- - test/couchdb/couch_has_many_test.rb
119
- - test/couchdb/couch_has_one_test.rb
120
- - test/couchdb/couch_instance_lifecycle_test.rb
121
- - test/couchdb/couch_mass_assignment_protection_test.rb
122
- - test/couchdb/couch_s3_test.rb
123
- - test/couchdb/couch_soft_deletable_test.rb
124
- - test/couchdb/couch_validations_test.rb
125
- - test/couchdb/custom_views_test.rb
112
+ - test/active_model_compatibility_test.rb
113
+ - test/belongs_to_test.rb
114
+ - test/conflict_handling_test.rb
115
+ - test/finder_test.rb
126
116
  - test/fixtures/couch.rb
127
- - test/fixtures/simpledb/item.rb
128
- - test/fixtures/simpledb/item_daddy.rb
129
- - test/fixtures/simpledb/log_item.rb
130
- - test/fixtures/simpledb/namespace_bar.rb
131
- - test/fixtures/simpledb/namespace_foo.rb
132
- - test/fixtures/simpledb/protected_item.rb
133
- - test/simply_stored_simpledb_test.rb
117
+ - test/has_and_belongs_to_many_test.rb
118
+ - test/has_many_test.rb
119
+ - test/has_one_test.rb
120
+ - test/instance_lifecycle_test.rb
121
+ - test/mass_assignment_protection_test.rb
122
+ - test/s3_test.rb
123
+ - test/soft_deletable_test.rb
134
124
  - test/test_helper.rb
135
- - test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb
136
- - test/vendor/dhaka-2.2.1/lib/dhaka/evaluator/evaluator.rb
137
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/closure_hash.rb
138
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar.rb
139
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar_symbol.rb
140
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/precedence.rb
141
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/production.rb
142
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/accept_actions.rb
143
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/alphabet.rb
144
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/compiled_lexer.rb
145
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/dfa.rb
146
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexeme.rb
147
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer.rb
148
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer_run.rb
149
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_grammar.rb
150
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_parser.rb
151
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_tokenizer.rb
152
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/specification.rb
153
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state.rb
154
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state_machine.rb
155
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/action.rb
156
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/channel.rb
157
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/compiled_parser.rb
158
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/conflict.rb
159
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/item.rb
160
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_result.rb
161
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_tree.rb
162
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser.rb
163
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_methods.rb
164
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_run.rb
165
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_state.rb
166
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/token.rb
167
- - test/vendor/dhaka-2.2.1/lib/dhaka/runtime.rb
168
- - test/vendor/dhaka-2.2.1/lib/dhaka/tokenizer/tokenizer.rb
169
- - test/vendor/dhaka-2.2.1/lib/dhaka.rb
170
- - test/vendor/dhaka-2.2.1/test/all_tests.rb
171
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator.rb
172
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator_test.rb
173
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar.rb
174
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar_test.rb
175
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_test_methods.rb
176
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer.rb
177
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer_test.rb
178
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_evaluator.rb
179
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar.rb
180
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar_test.rb
181
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_lexer_specification.rb
182
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_parser_test.rb
183
- - test/vendor/dhaka-2.2.1/test/brackets/bracket_grammar.rb
184
- - test/vendor/dhaka-2.2.1/test/brackets/bracket_tokenizer.rb
185
- - test/vendor/dhaka-2.2.1/test/brackets/brackets_test.rb
186
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver.rb
187
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver_test.rb
188
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator.rb
189
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator_test.rb
190
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_grammar.rb
191
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer.rb
192
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_specification.rb
193
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_test.rb
194
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser.rb
195
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser_test.rb
196
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_test.rb
197
- - test/vendor/dhaka-2.2.1/test/core/another_lalr_but_not_slr_grammar.rb
198
- - test/vendor/dhaka-2.2.1/test/core/compiled_parser_test.rb
199
- - test/vendor/dhaka-2.2.1/test/core/dfa_test.rb
200
- - test/vendor/dhaka-2.2.1/test/core/evaluator_test.rb
201
- - test/vendor/dhaka-2.2.1/test/core/grammar_test.rb
202
- - test/vendor/dhaka-2.2.1/test/core/lalr_but_not_slr_grammar.rb
203
- - test/vendor/dhaka-2.2.1/test/core/lexer_test.rb
204
- - test/vendor/dhaka-2.2.1/test/core/malformed_grammar.rb
205
- - test/vendor/dhaka-2.2.1/test/core/malformed_grammar_test.rb
206
- - test/vendor/dhaka-2.2.1/test/core/nullable_grammar.rb
207
- - test/vendor/dhaka-2.2.1/test/core/parse_result_test.rb
208
- - test/vendor/dhaka-2.2.1/test/core/parser_state_test.rb
209
- - test/vendor/dhaka-2.2.1/test/core/parser_test.rb
210
- - test/vendor/dhaka-2.2.1/test/core/precedence_grammar.rb
211
- - test/vendor/dhaka-2.2.1/test/core/precedence_grammar_test.rb
212
- - test/vendor/dhaka-2.2.1/test/core/rr_conflict_grammar.rb
213
- - test/vendor/dhaka-2.2.1/test/core/simple_grammar.rb
214
- - test/vendor/dhaka-2.2.1/test/core/sr_conflict_grammar.rb
215
- - test/vendor/dhaka-2.2.1/test/dhaka_test_helper.rb
216
- - test/vendor/dhaka-2.2.1/test/fake_logger.rb
217
- - test/vendor/simplerdb-0.2/lib/simplerdb/client_exception.rb
218
- - test/vendor/simplerdb-0.2/lib/simplerdb/db.rb
219
- - test/vendor/simplerdb-0.2/lib/simplerdb/query_language.rb
220
- - test/vendor/simplerdb-0.2/lib/simplerdb/server.rb
221
- - test/vendor/simplerdb-0.2/lib/simplerdb/servlet.rb
222
- - test/vendor/simplerdb-0.2/lib/simplerdb.rb
223
- - test/vendor/simplerdb-0.2/test/functional_test.rb
224
- - test/vendor/simplerdb-0.2/test/query_evaluator_test.rb
225
- - test/vendor/simplerdb-0.2/test/query_parser_test.rb
226
- - test/vendor/simplerdb-0.2/test/simplerdb_test.rb
125
+ - test/validations_test.rb
126
+ - test/views_test.rb
227
127
  has_rdoc: true
228
128
  homepage: http://github.com/peritor/simply_stored
229
129
  licenses: []
@@ -257,118 +157,20 @@ rubyforge_project:
257
157
  rubygems_version: 1.3.7
258
158
  signing_key:
259
159
  specification_version: 3
260
- summary: Convenience layer for CouchDB and SimpleDB
160
+ summary: Convenience layer for CouchDB
261
161
  test_files:
262
- - test/couchdb/couch_active_model_compatibility_test.rb
263
- - test/couchdb/couch_belongs_to_test.rb
264
- - test/couchdb/couch_conflict_handling_test.rb
265
- - test/couchdb/couch_finder_test.rb
266
- - test/couchdb/couch_has_many_test.rb
267
- - test/couchdb/couch_has_one_test.rb
268
- - test/couchdb/couch_instance_lifecycle_test.rb
269
- - test/couchdb/couch_mass_assignment_protection_test.rb
270
- - test/couchdb/couch_s3_test.rb
271
- - test/couchdb/couch_soft_deletable_test.rb
272
- - test/couchdb/couch_validations_test.rb
273
- - test/couchdb/custom_views_test.rb
162
+ - test/active_model_compatibility_test.rb
163
+ - test/belongs_to_test.rb
164
+ - test/conflict_handling_test.rb
165
+ - test/finder_test.rb
274
166
  - test/fixtures/couch.rb
275
- - test/fixtures/simpledb/item.rb
276
- - test/fixtures/simpledb/item_daddy.rb
277
- - test/fixtures/simpledb/log_item.rb
278
- - test/fixtures/simpledb/namespace_bar.rb
279
- - test/fixtures/simpledb/namespace_foo.rb
280
- - test/fixtures/simpledb/protected_item.rb
281
- - test/simply_stored_simpledb_test.rb
167
+ - test/has_and_belongs_to_many_test.rb
168
+ - test/has_many_test.rb
169
+ - test/has_one_test.rb
170
+ - test/instance_lifecycle_test.rb
171
+ - test/mass_assignment_protection_test.rb
172
+ - test/s3_test.rb
173
+ - test/soft_deletable_test.rb
282
174
  - test/test_helper.rb
283
- - test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb
284
- - test/vendor/dhaka-2.2.1/lib/dhaka/evaluator/evaluator.rb
285
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/closure_hash.rb
286
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar.rb
287
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar_symbol.rb
288
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/precedence.rb
289
- - test/vendor/dhaka-2.2.1/lib/dhaka/grammar/production.rb
290
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/accept_actions.rb
291
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/alphabet.rb
292
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/compiled_lexer.rb
293
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/dfa.rb
294
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexeme.rb
295
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer.rb
296
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer_run.rb
297
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_grammar.rb
298
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_parser.rb
299
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_tokenizer.rb
300
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/specification.rb
301
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state.rb
302
- - test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state_machine.rb
303
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/action.rb
304
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/channel.rb
305
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/compiled_parser.rb
306
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/conflict.rb
307
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/item.rb
308
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_result.rb
309
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_tree.rb
310
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser.rb
311
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_methods.rb
312
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_run.rb
313
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_state.rb
314
- - test/vendor/dhaka-2.2.1/lib/dhaka/parser/token.rb
315
- - test/vendor/dhaka-2.2.1/lib/dhaka/runtime.rb
316
- - test/vendor/dhaka-2.2.1/lib/dhaka/tokenizer/tokenizer.rb
317
- - test/vendor/dhaka-2.2.1/lib/dhaka.rb
318
- - test/vendor/dhaka-2.2.1/test/all_tests.rb
319
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator.rb
320
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator_test.rb
321
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar.rb
322
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar_test.rb
323
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_test_methods.rb
324
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer.rb
325
- - test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer_test.rb
326
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_evaluator.rb
327
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar.rb
328
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar_test.rb
329
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_lexer_specification.rb
330
- - test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_parser_test.rb
331
- - test/vendor/dhaka-2.2.1/test/brackets/bracket_grammar.rb
332
- - test/vendor/dhaka-2.2.1/test/brackets/bracket_tokenizer.rb
333
- - test/vendor/dhaka-2.2.1/test/brackets/brackets_test.rb
334
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver.rb
335
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver_test.rb
336
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator.rb
337
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator_test.rb
338
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_grammar.rb
339
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer.rb
340
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_specification.rb
341
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_test.rb
342
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser.rb
343
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser_test.rb
344
- - test/vendor/dhaka-2.2.1/test/chittagong/chittagong_test.rb
345
- - test/vendor/dhaka-2.2.1/test/core/another_lalr_but_not_slr_grammar.rb
346
- - test/vendor/dhaka-2.2.1/test/core/compiled_parser_test.rb
347
- - test/vendor/dhaka-2.2.1/test/core/dfa_test.rb
348
- - test/vendor/dhaka-2.2.1/test/core/evaluator_test.rb
349
- - test/vendor/dhaka-2.2.1/test/core/grammar_test.rb
350
- - test/vendor/dhaka-2.2.1/test/core/lalr_but_not_slr_grammar.rb
351
- - test/vendor/dhaka-2.2.1/test/core/lexer_test.rb
352
- - test/vendor/dhaka-2.2.1/test/core/malformed_grammar.rb
353
- - test/vendor/dhaka-2.2.1/test/core/malformed_grammar_test.rb
354
- - test/vendor/dhaka-2.2.1/test/core/nullable_grammar.rb
355
- - test/vendor/dhaka-2.2.1/test/core/parse_result_test.rb
356
- - test/vendor/dhaka-2.2.1/test/core/parser_state_test.rb
357
- - test/vendor/dhaka-2.2.1/test/core/parser_test.rb
358
- - test/vendor/dhaka-2.2.1/test/core/precedence_grammar.rb
359
- - test/vendor/dhaka-2.2.1/test/core/precedence_grammar_test.rb
360
- - test/vendor/dhaka-2.2.1/test/core/rr_conflict_grammar.rb
361
- - test/vendor/dhaka-2.2.1/test/core/simple_grammar.rb
362
- - test/vendor/dhaka-2.2.1/test/core/sr_conflict_grammar.rb
363
- - test/vendor/dhaka-2.2.1/test/dhaka_test_helper.rb
364
- - test/vendor/dhaka-2.2.1/test/fake_logger.rb
365
- - test/vendor/simplerdb-0.2/lib/simplerdb/client_exception.rb
366
- - test/vendor/simplerdb-0.2/lib/simplerdb/db.rb
367
- - test/vendor/simplerdb-0.2/lib/simplerdb/query_language.rb
368
- - test/vendor/simplerdb-0.2/lib/simplerdb/server.rb
369
- - test/vendor/simplerdb-0.2/lib/simplerdb/servlet.rb
370
- - test/vendor/simplerdb-0.2/lib/simplerdb.rb
371
- - test/vendor/simplerdb-0.2/test/functional_test.rb
372
- - test/vendor/simplerdb-0.2/test/query_evaluator_test.rb
373
- - test/vendor/simplerdb-0.2/test/query_parser_test.rb
374
- - test/vendor/simplerdb-0.2/test/simplerdb_test.rb
175
+ - test/validations_test.rb
176
+ - test/views_test.rb
@@ -1,215 +0,0 @@
1
- module SimplyStored
2
- module SimpleDB
3
- module Associations
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def belongs_to(name, options = nil)
10
- options = {
11
- :class_name => self.formalize_class_name(name),
12
- :foreign_key => "#{name}_id"
13
- }.update(options || {})
14
- define_belongs_to_getter(name, options)
15
- define_belongs_to_setter(name, options)
16
- end
17
-
18
- def has_one(name, options = {})
19
- options = {
20
- :clear => :nullify, # or :destroy
21
- :dependent => :nullify, # or :destroy
22
- :class_name => self.formalize_class_name(name),
23
- :foreign_key => self.foreign_key
24
- }.update(options)
25
-
26
- define_has_one_getter(name, options)
27
- define_has_one_setter(name, options)
28
- define_has_one_dependent_clearing(name, options)
29
- end
30
-
31
- def has_many(name, options = {})
32
- options = {
33
- :clear => :nullify, # or :destroy
34
- :dependent => :nullify, # or :destroy
35
- :class_name => self.formalize_class_name(name.to_s.singularize),
36
- :foreign_key => self.foreign_key
37
- }.update(options)
38
-
39
- define_has_many_getter(name, options)
40
- define_has_many_setter_add(name, options)
41
- define_has_many_setter_remove(name, options)
42
- define_has_many_setter_remove_all(name, options)
43
- define_has_many_dependent_clearing(name, options)
44
- end
45
-
46
- def define_belongs_to_getter(name, options)
47
- foreign_key_column = options[:foreign_key]
48
- define_method(name.to_s) do
49
- klass = options[:class_name].constantize
50
- cached_version = instance_variable_get("@_cached_belongs_to_#{name}")
51
- if cached_version.nil? and self[foreign_key_column].present?
52
- cached_version = klass.find(self.send(foreign_key_column), :auto_load => true)
53
- instance_variable_set("@_cached_belongs_to_#{name}", cached_version)
54
- end
55
- cached_version
56
- end
57
- end
58
-
59
- def define_belongs_to_setter(name, options)
60
- foreign_key_column = options[:foreign_key]
61
- define_method("#{name}=") do |val|
62
- klass = options[:class_name].constantize
63
- raise ArgumentError, "expected #{klass} got #{val.class}" unless val.is_a?(klass)
64
- self.send("#{foreign_key_column}=", val.id)
65
- instance_variable_set("@_cached_belongs_to_#{name}", val)
66
- end
67
- end
68
-
69
- def define_has_one_getter(name, options)
70
- foreign_key_column = options[:foreign_key]
71
- define_method(name.to_s) do
72
- klass = options[:class_name].constantize
73
- cached_version = instance_variable_get("@_cached_has_one_#{name}")
74
- if cached_version
75
- cached_version
76
- else
77
- cached_version = klass.send("find_by_#{foreign_key_column}".to_sym, self.id, {:auto_load => true})
78
- instance_variable_set("@_cached_has_one_#{name}", cached_version)
79
- cached_version
80
- end
81
- end
82
- end
83
-
84
- def define_has_one_setter(name, options)
85
- foreign_key_column = options[:foreign_key]
86
- define_method("#{name}=") do |val|
87
- klass = options[:class_name].constantize
88
- raise ArgumentError, "expected #{klass} got #{val.class}" unless val.is_a?(klass)
89
-
90
- # clear old
91
- old = self.send("#{name}")
92
- old.send("#{foreign_key_column}=", nil) if old && options[:clear] == :nullify
93
- old.delete if old && options[:clear] == :destroy
94
-
95
- # store new
96
- val.send("#{foreign_key_column}=", self.id)
97
- instance_variable_set("@_cached_has_one_#{name}", val)
98
- end
99
- end
100
-
101
- def define_has_one_dependent_clearing(name, options)
102
- # add method to list of methods to run when deleted
103
- @_clear_dependents_after_delete_methods ||= []
104
- @_clear_dependents_after_delete_methods << "has_one_clear_#{name}_after_destroy"
105
-
106
- # define actual clearing/deleting
107
- foreign_key_column = options[:foreign_key]
108
- define_method("has_one_clear_#{name}_after_destroy") do
109
- klass = options[:class_name].constantize
110
- dependent = klass.send("find_by_#{foreign_key_column}".to_sym, self.id)
111
- case options[:dependent]
112
- when :nullify then
113
- dependent.send("#{foreign_key_column}=", nil) if dependent
114
- when :destroy then
115
- dependent.delete if dependent
116
- else
117
- raise ArgumentError, "unknown dependent method: #{options[:dependent].inspect}"
118
- end
119
- end
120
- end
121
-
122
- def define_has_many_getter(name, options)
123
- foreign_key_column = options[:foreign_key]
124
- define_method(name.to_s) do
125
- klass = options[:class_name].constantize
126
- cached_version = instance_variable_get("@_cached_has_many_#{name}")
127
- if cached_version
128
- cached_version
129
- else
130
- cached_version = klass.send("find_all_by_#{foreign_key_column}".to_sym, self.id, {:auto_load => true})
131
- instance_variable_set("@_cached_has_many_#{name}", cached_version)
132
- cached_version
133
- end
134
- end
135
- end
136
-
137
- def define_has_many_setter_add(name, options)
138
- foreign_key_column = options[:foreign_key]
139
- define_method("add_#{name.to_s.singularize}") do |val|
140
- klass = options[:class_name].constantize
141
- raise ArgumentError, "expected #{klass} got #{val.class}" unless val.is_a?(klass)
142
- val.send("#{foreign_key_column}=", self.id)
143
- val.save(false)
144
- cached_version = instance_variable_get("@_cached_has_many_#{name}") || []
145
- instance_variable_set("@_cached_has_many_#{name}", cached_version << val)
146
- end
147
- end
148
-
149
- def define_has_many_setter_remove(name, options)
150
- foreign_key_column = options[:foreign_key]
151
- define_method("remove_#{name.to_s.singularize}") do |val|
152
- klass = options[:class_name].constantize
153
- raise ArgumentError, "expected #{klass} got #{val.class}" unless val.is_a?(klass)
154
- raise ArgumentError, "cannot remove not mine" unless val.send(foreign_key_column) == self.id
155
- case options[:clear]
156
- when :nullify then
157
- val.send("#{foreign_key_column}=", nil)
158
- val.save(false)
159
- when :destroy then
160
- val.delete
161
- else
162
- raise "Unknown option for clear: #{option[:clear]}"
163
- end
164
- cached_version = instance_variable_get("@_cached_has_many_#{name}") || []
165
- instance_variable_set("@_cached_has_many_#{name}", cached_version.delete_if{|x| x.id == val.id})
166
- end
167
- end
168
-
169
- def define_has_many_setter_remove_all(name, options)
170
- foreign_key_column = options[:foreign_key]
171
- define_method("remove_all_#{name}") do
172
- klass = options[:class_name].constantize
173
- all = klass.send("find_all_by_#{foreign_key_column}".to_sym, self.id)
174
- all.each do |item|
175
- self.send("remove_#{name.to_s.singularize}", item)
176
- end
177
- instance_variable_set("@_cached_has_many_#{name}", [])
178
- end
179
- end
180
-
181
- def define_has_many_dependent_clearing(name, options)
182
- # add method to list of methods to run when deleted
183
- @_clear_dependents_after_delete_methods ||= []
184
- @_clear_dependents_after_delete_methods << "has_many_clear_#{name}_after_destroy"
185
-
186
- # define actual clearing/deleting
187
- foreign_key_column = options[:foreign_key]
188
- define_method("has_many_clear_#{name}_after_destroy") do
189
- klass = options[:class_name].constantize
190
- dependents = klass.send("find_all_by_#{foreign_key_column}".to_sym, self.id)
191
- case options[:dependent]
192
- when :nullify then
193
- dependents.each do |dependent|
194
- dependent.send("#{foreign_key_column}=", nil)
195
- end
196
- when :destroy then
197
- dependents.each do |dependent|
198
- dependent.delete
199
- end
200
- else
201
- raise ArgumentError, "unknown dependent method: #{options[:dependent].inspect}"
202
- end
203
- end
204
- end
205
- end
206
-
207
- def clear_dependents_after_delete
208
- clear_methods = self.class.instance_variable_get("@_clear_dependents_after_delete_methods") || []
209
- clear_methods.uniq.each do |clear_method|
210
- self.send(clear_method)
211
- end
212
- end
213
- end
214
- end
215
- end