activerecord 3.2.22.4 → 4.0.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2799 -617
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +23 -32
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record/aggregations.rb +40 -34
  7. data/lib/active_record/association_relation.rb +22 -0
  8. data/lib/active_record/associations/alias_tracker.rb +4 -2
  9. data/lib/active_record/associations/association.rb +60 -46
  10. data/lib/active_record/associations/association_scope.rb +46 -40
  11. data/lib/active_record/associations/belongs_to_association.rb +17 -4
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
  13. data/lib/active_record/associations/builder/association.rb +81 -28
  14. data/lib/active_record/associations/builder/belongs_to.rb +73 -56
  15. data/lib/active_record/associations/builder/collection_association.rb +54 -40
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
  17. data/lib/active_record/associations/builder/has_many.rb +8 -64
  18. data/lib/active_record/associations/builder/has_one.rb +13 -50
  19. data/lib/active_record/associations/builder/singular_association.rb +13 -13
  20. data/lib/active_record/associations/collection_association.rb +130 -96
  21. data/lib/active_record/associations/collection_proxy.rb +916 -63
  22. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +15 -13
  23. data/lib/active_record/associations/has_many_association.rb +35 -8
  24. data/lib/active_record/associations/has_many_through_association.rb +37 -17
  25. data/lib/active_record/associations/has_one_association.rb +42 -19
  26. data/lib/active_record/associations/has_one_through_association.rb +1 -1
  27. data/lib/active_record/associations/join_dependency/join_association.rb +39 -22
  28. data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
  29. data/lib/active_record/associations/join_dependency/join_part.rb +21 -8
  30. data/lib/active_record/associations/join_dependency.rb +30 -9
  31. data/lib/active_record/associations/join_helper.rb +1 -11
  32. data/lib/active_record/associations/preloader/association.rb +29 -33
  33. data/lib/active_record/associations/preloader/collection_association.rb +1 -1
  34. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +2 -2
  35. data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
  36. data/lib/active_record/associations/preloader/has_one.rb +1 -1
  37. data/lib/active_record/associations/preloader/through_association.rb +13 -17
  38. data/lib/active_record/associations/preloader.rb +20 -43
  39. data/lib/active_record/associations/singular_association.rb +11 -11
  40. data/lib/active_record/associations/through_association.rb +3 -3
  41. data/lib/active_record/associations.rb +223 -282
  42. data/lib/active_record/attribute_assignment.rb +134 -154
  43. data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
  44. data/lib/active_record/attribute_methods/dirty.rb +36 -29
  45. data/lib/active_record/attribute_methods/primary_key.rb +45 -31
  46. data/lib/active_record/attribute_methods/query.rb +5 -4
  47. data/lib/active_record/attribute_methods/read.rb +67 -90
  48. data/lib/active_record/attribute_methods/serialization.rb +133 -70
  49. data/lib/active_record/attribute_methods/time_zone_conversion.rb +51 -45
  50. data/lib/active_record/attribute_methods/write.rb +34 -39
  51. data/lib/active_record/attribute_methods.rb +268 -108
  52. data/lib/active_record/autosave_association.rb +80 -73
  53. data/lib/active_record/base.rb +54 -451
  54. data/lib/active_record/callbacks.rb +60 -22
  55. data/lib/active_record/coders/yaml_column.rb +18 -21
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +347 -197
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +146 -138
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +25 -19
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +19 -3
  61. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +151 -142
  62. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
  63. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +499 -217
  64. data/lib/active_record/connection_adapters/abstract/transaction.rb +208 -0
  65. data/lib/active_record/connection_adapters/abstract_adapter.rb +209 -44
  66. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +169 -61
  67. data/lib/active_record/connection_adapters/column.rb +67 -36
  68. data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
  69. data/lib/active_record/connection_adapters/mysql2_adapter.rb +28 -29
  70. data/lib/active_record/connection_adapters/mysql_adapter.rb +200 -73
  71. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +98 -0
  72. data/lib/active_record/connection_adapters/postgresql/cast.rb +160 -0
  73. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +240 -0
  74. data/lib/active_record/connection_adapters/postgresql/oid.rb +374 -0
  75. data/lib/active_record/connection_adapters/postgresql/quoting.rb +183 -0
  76. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
  77. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +508 -0
  78. data/lib/active_record/connection_adapters/postgresql_adapter.rb +544 -899
  79. data/lib/active_record/connection_adapters/schema_cache.rb +76 -16
  80. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +595 -16
  81. data/lib/active_record/connection_handling.rb +98 -0
  82. data/lib/active_record/core.rb +472 -0
  83. data/lib/active_record/counter_cache.rb +107 -108
  84. data/lib/active_record/dynamic_matchers.rb +115 -63
  85. data/lib/active_record/errors.rb +36 -18
  86. data/lib/active_record/explain.rb +15 -63
  87. data/lib/active_record/explain_registry.rb +30 -0
  88. data/lib/active_record/explain_subscriber.rb +8 -4
  89. data/lib/active_record/fixture_set/file.rb +55 -0
  90. data/lib/active_record/fixtures.rb +159 -155
  91. data/lib/active_record/inheritance.rb +93 -59
  92. data/lib/active_record/integration.rb +8 -8
  93. data/lib/active_record/locale/en.yml +8 -1
  94. data/lib/active_record/locking/optimistic.rb +39 -43
  95. data/lib/active_record/locking/pessimistic.rb +4 -4
  96. data/lib/active_record/log_subscriber.rb +19 -9
  97. data/lib/active_record/migration/command_recorder.rb +102 -33
  98. data/lib/active_record/migration/join_table.rb +15 -0
  99. data/lib/active_record/migration.rb +411 -173
  100. data/lib/active_record/model_schema.rb +81 -94
  101. data/lib/active_record/nested_attributes.rb +173 -131
  102. data/lib/active_record/null_relation.rb +67 -0
  103. data/lib/active_record/persistence.rb +254 -106
  104. data/lib/active_record/query_cache.rb +18 -36
  105. data/lib/active_record/querying.rb +19 -15
  106. data/lib/active_record/railtie.rb +113 -38
  107. data/lib/active_record/railties/console_sandbox.rb +3 -4
  108. data/lib/active_record/railties/controller_runtime.rb +4 -3
  109. data/lib/active_record/railties/databases.rake +115 -368
  110. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  111. data/lib/active_record/readonly_attributes.rb +7 -3
  112. data/lib/active_record/reflection.rb +110 -61
  113. data/lib/active_record/relation/batches.rb +29 -29
  114. data/lib/active_record/relation/calculations.rb +155 -125
  115. data/lib/active_record/relation/delegation.rb +94 -18
  116. data/lib/active_record/relation/finder_methods.rb +151 -203
  117. data/lib/active_record/relation/merger.rb +188 -0
  118. data/lib/active_record/relation/predicate_builder.rb +85 -42
  119. data/lib/active_record/relation/query_methods.rb +793 -146
  120. data/lib/active_record/relation/spawn_methods.rb +43 -150
  121. data/lib/active_record/relation.rb +293 -173
  122. data/lib/active_record/result.rb +48 -7
  123. data/lib/active_record/runtime_registry.rb +17 -0
  124. data/lib/active_record/sanitization.rb +41 -54
  125. data/lib/active_record/schema.rb +19 -12
  126. data/lib/active_record/schema_dumper.rb +41 -41
  127. data/lib/active_record/schema_migration.rb +46 -0
  128. data/lib/active_record/scoping/default.rb +56 -52
  129. data/lib/active_record/scoping/named.rb +78 -103
  130. data/lib/active_record/scoping.rb +54 -124
  131. data/lib/active_record/serialization.rb +6 -2
  132. data/lib/active_record/serializers/xml_serializer.rb +9 -15
  133. data/lib/active_record/statement_cache.rb +26 -0
  134. data/lib/active_record/store.rb +131 -15
  135. data/lib/active_record/tasks/database_tasks.rb +204 -0
  136. data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
  137. data/lib/active_record/tasks/mysql_database_tasks.rb +144 -0
  138. data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
  139. data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
  140. data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
  141. data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
  142. data/lib/active_record/test_case.rb +67 -38
  143. data/lib/active_record/timestamp.rb +16 -11
  144. data/lib/active_record/transactions.rb +73 -51
  145. data/lib/active_record/validations/associated.rb +19 -13
  146. data/lib/active_record/validations/presence.rb +65 -0
  147. data/lib/active_record/validations/uniqueness.rb +110 -57
  148. data/lib/active_record/validations.rb +18 -17
  149. data/lib/active_record/version.rb +7 -6
  150. data/lib/active_record.rb +63 -45
  151. data/lib/rails/generators/active_record/migration/migration_generator.rb +45 -8
  152. data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
  153. data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
  154. data/lib/rails/generators/active_record/model/model_generator.rb +5 -4
  155. data/lib/rails/generators/active_record/model/templates/model.rb +4 -6
  156. data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
  157. data/lib/rails/generators/active_record.rb +3 -5
  158. metadata +43 -29
  159. data/examples/associations.png +0 -0
  160. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
  161. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
  162. data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
  163. data/lib/active_record/dynamic_finder_match.rb +0 -68
  164. data/lib/active_record/dynamic_scope_match.rb +0 -23
  165. data/lib/active_record/fixtures/file.rb +0 -65
  166. data/lib/active_record/identity_map.rb +0 -162
  167. data/lib/active_record/observer.rb +0 -121
  168. data/lib/active_record/session_store.rb +0 -360
  169. data/lib/rails/generators/active_record/migration.rb +0 -15
  170. data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
  171. data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
  172. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
  173. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.22.4
4
+ version: 4.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.22.4
19
+ version: 4.0.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.22.4
26
+ version: 4.0.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.22.4
33
+ version: 4.0.13
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.2.22.4
40
+ version: 4.0.13
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.2
47
+ version: 4.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.2
54
+ version: 4.0.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: tzinfo
56
+ name: activerecord-deprecated_finders
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.29
61
+ version: 1.0.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.3.29
68
+ version: 1.0.2
69
69
  description: Databases on Rails. Build a persistent domain model by mapping database
70
70
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
71
71
  migrations, and testing come baked-in.
@@ -78,11 +78,11 @@ files:
78
78
  - CHANGELOG.md
79
79
  - MIT-LICENSE
80
80
  - README.rdoc
81
- - examples/associations.png
82
81
  - examples/performance.rb
83
82
  - examples/simple.rb
84
83
  - lib/active_record.rb
85
84
  - lib/active_record/aggregations.rb
85
+ - lib/active_record/association_relation.rb
86
86
  - lib/active_record/associations.rb
87
87
  - lib/active_record/associations/alias_tracker.rb
88
88
  - lib/active_record/associations/association.rb
@@ -124,7 +124,6 @@ files:
124
124
  - lib/active_record/attribute_assignment.rb
125
125
  - lib/active_record/attribute_methods.rb
126
126
  - lib/active_record/attribute_methods/before_type_cast.rb
127
- - lib/active_record/attribute_methods/deprecated_underscore_read.rb
128
127
  - lib/active_record/attribute_methods/dirty.rb
129
128
  - lib/active_record/attribute_methods/primary_key.rb
130
129
  - lib/active_record/attribute_methods/query.rb
@@ -137,33 +136,41 @@ files:
137
136
  - lib/active_record/callbacks.rb
138
137
  - lib/active_record/coders/yaml_column.rb
139
138
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
140
- - lib/active_record/connection_adapters/abstract/connection_specification.rb
141
139
  - lib/active_record/connection_adapters/abstract/database_limits.rb
142
140
  - lib/active_record/connection_adapters/abstract/database_statements.rb
143
141
  - lib/active_record/connection_adapters/abstract/query_cache.rb
144
142
  - lib/active_record/connection_adapters/abstract/quoting.rb
145
143
  - lib/active_record/connection_adapters/abstract/schema_definitions.rb
144
+ - lib/active_record/connection_adapters/abstract/schema_dumper.rb
146
145
  - lib/active_record/connection_adapters/abstract/schema_statements.rb
146
+ - lib/active_record/connection_adapters/abstract/transaction.rb
147
147
  - lib/active_record/connection_adapters/abstract_adapter.rb
148
148
  - lib/active_record/connection_adapters/abstract_mysql_adapter.rb
149
149
  - lib/active_record/connection_adapters/column.rb
150
+ - lib/active_record/connection_adapters/connection_specification.rb
150
151
  - lib/active_record/connection_adapters/mysql2_adapter.rb
151
152
  - lib/active_record/connection_adapters/mysql_adapter.rb
153
+ - lib/active_record/connection_adapters/postgresql/array_parser.rb
154
+ - lib/active_record/connection_adapters/postgresql/cast.rb
155
+ - lib/active_record/connection_adapters/postgresql/database_statements.rb
156
+ - lib/active_record/connection_adapters/postgresql/oid.rb
157
+ - lib/active_record/connection_adapters/postgresql/quoting.rb
158
+ - lib/active_record/connection_adapters/postgresql/referential_integrity.rb
159
+ - lib/active_record/connection_adapters/postgresql/schema_statements.rb
152
160
  - lib/active_record/connection_adapters/postgresql_adapter.rb
153
161
  - lib/active_record/connection_adapters/schema_cache.rb
154
162
  - lib/active_record/connection_adapters/sqlite3_adapter.rb
155
- - lib/active_record/connection_adapters/sqlite_adapter.rb
156
163
  - lib/active_record/connection_adapters/statement_pool.rb
164
+ - lib/active_record/connection_handling.rb
165
+ - lib/active_record/core.rb
157
166
  - lib/active_record/counter_cache.rb
158
- - lib/active_record/dynamic_finder_match.rb
159
167
  - lib/active_record/dynamic_matchers.rb
160
- - lib/active_record/dynamic_scope_match.rb
161
168
  - lib/active_record/errors.rb
162
169
  - lib/active_record/explain.rb
170
+ - lib/active_record/explain_registry.rb
163
171
  - lib/active_record/explain_subscriber.rb
172
+ - lib/active_record/fixture_set/file.rb
164
173
  - lib/active_record/fixtures.rb
165
- - lib/active_record/fixtures/file.rb
166
- - lib/active_record/identity_map.rb
167
174
  - lib/active_record/inheritance.rb
168
175
  - lib/active_record/integration.rb
169
176
  - lib/active_record/locale/en.yml
@@ -172,9 +179,10 @@ files:
172
179
  - lib/active_record/log_subscriber.rb
173
180
  - lib/active_record/migration.rb
174
181
  - lib/active_record/migration/command_recorder.rb
182
+ - lib/active_record/migration/join_table.rb
175
183
  - lib/active_record/model_schema.rb
176
184
  - lib/active_record/nested_attributes.rb
177
- - lib/active_record/observer.rb
185
+ - lib/active_record/null_relation.rb
178
186
  - lib/active_record/persistence.rb
179
187
  - lib/active_record/query_cache.rb
180
188
  - lib/active_record/querying.rb
@@ -190,40 +198,46 @@ files:
190
198
  - lib/active_record/relation/calculations.rb
191
199
  - lib/active_record/relation/delegation.rb
192
200
  - lib/active_record/relation/finder_methods.rb
201
+ - lib/active_record/relation/merger.rb
193
202
  - lib/active_record/relation/predicate_builder.rb
194
203
  - lib/active_record/relation/query_methods.rb
195
204
  - lib/active_record/relation/spawn_methods.rb
196
205
  - lib/active_record/result.rb
206
+ - lib/active_record/runtime_registry.rb
197
207
  - lib/active_record/sanitization.rb
198
208
  - lib/active_record/schema.rb
199
209
  - lib/active_record/schema_dumper.rb
210
+ - lib/active_record/schema_migration.rb
200
211
  - lib/active_record/scoping.rb
201
212
  - lib/active_record/scoping/default.rb
202
213
  - lib/active_record/scoping/named.rb
203
214
  - lib/active_record/serialization.rb
204
215
  - lib/active_record/serializers/xml_serializer.rb
205
- - lib/active_record/session_store.rb
216
+ - lib/active_record/statement_cache.rb
206
217
  - lib/active_record/store.rb
218
+ - lib/active_record/tasks/database_tasks.rb
219
+ - lib/active_record/tasks/firebird_database_tasks.rb
220
+ - lib/active_record/tasks/mysql_database_tasks.rb
221
+ - lib/active_record/tasks/oracle_database_tasks.rb
222
+ - lib/active_record/tasks/postgresql_database_tasks.rb
223
+ - lib/active_record/tasks/sqlite_database_tasks.rb
224
+ - lib/active_record/tasks/sqlserver_database_tasks.rb
207
225
  - lib/active_record/test_case.rb
208
226
  - lib/active_record/timestamp.rb
209
227
  - lib/active_record/transactions.rb
210
228
  - lib/active_record/translation.rb
211
229
  - lib/active_record/validations.rb
212
230
  - lib/active_record/validations/associated.rb
231
+ - lib/active_record/validations/presence.rb
213
232
  - lib/active_record/validations/uniqueness.rb
214
233
  - lib/active_record/version.rb
215
234
  - lib/rails/generators/active_record.rb
216
- - lib/rails/generators/active_record/migration.rb
217
235
  - lib/rails/generators/active_record/migration/migration_generator.rb
236
+ - lib/rails/generators/active_record/migration/templates/create_table_migration.rb
218
237
  - lib/rails/generators/active_record/migration/templates/migration.rb
219
238
  - lib/rails/generators/active_record/model/model_generator.rb
220
- - lib/rails/generators/active_record/model/templates/migration.rb
221
239
  - lib/rails/generators/active_record/model/templates/model.rb
222
240
  - lib/rails/generators/active_record/model/templates/module.rb
223
- - lib/rails/generators/active_record/observer/observer_generator.rb
224
- - lib/rails/generators/active_record/observer/templates/observer.rb
225
- - lib/rails/generators/active_record/session_migration/session_migration_generator.rb
226
- - lib/rails/generators/active_record/session_migration/templates/migration.rb
227
241
  homepage: http://www.rubyonrails.org
228
242
  licenses:
229
243
  - MIT
@@ -238,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
252
  requirements:
239
253
  - - ">="
240
254
  - !ruby/object:Gem::Version
241
- version: 1.8.7
255
+ version: 1.9.3
242
256
  required_rubygems_version: !ruby/object:Gem::Requirement
243
257
  requirements:
244
258
  - - ">="
@@ -246,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
260
  version: '0'
247
261
  requirements: []
248
262
  rubyforge_project:
249
- rubygems_version: 2.5.1
263
+ rubygems_version: 2.4.5
250
264
  signing_key:
251
265
  specification_version: 4
252
266
  summary: Object-relational mapper framework (part of Rails).
Binary file
@@ -1,32 +0,0 @@
1
- require 'active_support/concern'
2
- require 'active_support/deprecation'
3
-
4
- module ActiveRecord
5
- module AttributeMethods
6
- module DeprecatedUnderscoreRead
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- attribute_method_prefix "_"
11
- end
12
-
13
- module ClassMethods
14
- protected
15
-
16
- def define_method__attribute(attr_name)
17
- # Do nothing, let it hit method missing instead.
18
- end
19
- end
20
-
21
- protected
22
-
23
- def _attribute(attr_name)
24
- ActiveSupport::Deprecation.warn(
25
- "You have called '_#{attr_name}'. This is deprecated. Please use " \
26
- "either '#{attr_name}' or read_attribute('#{attr_name}')."
27
- )
28
- read_attribute(attr_name)
29
- end
30
- end
31
- end
32
- end
@@ -1,191 +0,0 @@
1
- require 'uri'
2
-
3
- module ActiveRecord
4
- class Base
5
- class ConnectionSpecification #:nodoc:
6
- attr_reader :config, :adapter_method
7
- def initialize (config, adapter_method)
8
- @config, @adapter_method = config, adapter_method
9
- end
10
-
11
- ##
12
- # Builds a ConnectionSpecification from user input
13
- class Resolver # :nodoc:
14
- attr_reader :config, :klass, :configurations
15
-
16
- def initialize(config, configurations)
17
- @config = config
18
- @configurations = configurations
19
- end
20
-
21
- def spec
22
- case config
23
- when nil
24
- raise AdapterNotSpecified unless defined?(Rails.env)
25
- resolve_string_connection Rails.env
26
- when Symbol, String
27
- resolve_string_connection config.to_s
28
- when Hash
29
- resolve_hash_connection config
30
- end
31
- end
32
-
33
- private
34
- def resolve_string_connection(spec) # :nodoc:
35
- hash = configurations.fetch(spec) do |k|
36
- connection_url_to_hash(k)
37
- end
38
-
39
- raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash
40
-
41
- resolve_hash_connection hash
42
- end
43
-
44
- def resolve_hash_connection(spec) # :nodoc:
45
- spec = spec.symbolize_keys
46
-
47
- raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
48
-
49
- begin
50
- require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
51
- rescue LoadError => e
52
- raise LoadError, "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{e.message})", e.backtrace
53
- end
54
-
55
- adapter_method = "#{spec[:adapter]}_connection"
56
-
57
- ConnectionSpecification.new(spec, adapter_method)
58
- end
59
-
60
- def connection_url_to_hash(url) # :nodoc:
61
- config = URI.parse url
62
- adapter = config.scheme
63
- adapter = "postgresql" if adapter == "postgres"
64
- spec = { :adapter => adapter,
65
- :username => config.user,
66
- :password => config.password,
67
- :port => config.port,
68
- :database => config.path.sub(%r{^/},""),
69
- :host => config.host }
70
- spec.reject!{ |_,value| value.blank? }
71
- spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) }
72
- if config.query
73
- options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
74
- spec.merge!(options)
75
- end
76
- spec
77
- end
78
- end
79
- end
80
-
81
- ##
82
- # :singleton-method:
83
- # The connection handler
84
- class_attribute :connection_handler, :instance_writer => false
85
- self.connection_handler = ConnectionAdapters::ConnectionHandler.new
86
-
87
- # Returns the connection currently associated with the class. This can
88
- # also be used to "borrow" the connection to do database work that isn't
89
- # easily done without going straight to SQL.
90
- def connection
91
- self.class.connection
92
- end
93
-
94
- # Establishes the connection to the database. Accepts a hash as input where
95
- # the <tt>:adapter</tt> key must be specified with the name of a database adapter (in lower-case)
96
- # example for regular databases (MySQL, Postgresql, etc):
97
- #
98
- # ActiveRecord::Base.establish_connection(
99
- # :adapter => "mysql",
100
- # :host => "localhost",
101
- # :username => "myuser",
102
- # :password => "mypass",
103
- # :database => "somedatabase"
104
- # )
105
- #
106
- # Example for SQLite database:
107
- #
108
- # ActiveRecord::Base.establish_connection(
109
- # :adapter => "sqlite",
110
- # :database => "path/to/dbfile"
111
- # )
112
- #
113
- # Also accepts keys as strings (for parsing from YAML for example):
114
- #
115
- # ActiveRecord::Base.establish_connection(
116
- # "adapter" => "sqlite",
117
- # "database" => "path/to/dbfile"
118
- # )
119
- #
120
- # Or a URL:
121
- #
122
- # ActiveRecord::Base.establish_connection(
123
- # "postgres://myuser:mypass@localhost/somedatabase"
124
- # )
125
- #
126
- # The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError
127
- # may be returned on an error.
128
- def self.establish_connection(spec = ENV["DATABASE_URL"])
129
- resolver = ConnectionSpecification::Resolver.new spec, configurations
130
- spec = resolver.spec
131
-
132
- unless respond_to?(spec.adapter_method)
133
- raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
134
- end
135
-
136
- remove_connection
137
- connection_handler.establish_connection name, spec
138
- end
139
-
140
- class << self
141
- # Returns the connection currently associated with the class. This can
142
- # also be used to "borrow" the connection to do database work unrelated
143
- # to any of the specific Active Records.
144
- def connection
145
- retrieve_connection
146
- end
147
-
148
- def connection_id
149
- Thread.current['ActiveRecord::Base.connection_id']
150
- end
151
-
152
- def connection_id=(connection_id)
153
- Thread.current['ActiveRecord::Base.connection_id'] = connection_id
154
- end
155
-
156
- # Returns the configuration of the associated connection as a hash:
157
- #
158
- # ActiveRecord::Base.connection_config
159
- # # => {:pool=>5, :timeout=>5000, :database=>"db/development.sqlite3", :adapter=>"sqlite3"}
160
- #
161
- # Please use only for reading.
162
- def connection_config
163
- connection_pool.spec.config
164
- end
165
-
166
- def connection_pool
167
- connection_handler.retrieve_connection_pool(self) or raise ConnectionNotEstablished
168
- end
169
-
170
- def retrieve_connection
171
- connection_handler.retrieve_connection(self)
172
- end
173
-
174
- # Returns true if Active Record is connected.
175
- def connected?
176
- connection_handler.connected?(self)
177
- end
178
-
179
- def remove_connection(klass = self)
180
- connection_handler.remove_connection(klass)
181
- end
182
-
183
- def clear_active_connections!
184
- connection_handler.clear_active_connections!
185
- end
186
-
187
- delegate :clear_reloadable_connections!,
188
- :clear_all_connections!,:verify_active_connections!, :to => :connection_handler
189
- end
190
- end
191
- end