activerecord 4.2.0 → 5.2.8.1

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 (274) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +640 -928
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +10 -11
  5. data/examples/performance.rb +32 -31
  6. data/examples/simple.rb +5 -4
  7. data/lib/active_record/aggregations.rb +264 -247
  8. data/lib/active_record/association_relation.rb +24 -6
  9. data/lib/active_record/associations/alias_tracker.rb +29 -35
  10. data/lib/active_record/associations/association.rb +87 -41
  11. data/lib/active_record/associations/association_scope.rb +106 -132
  12. data/lib/active_record/associations/belongs_to_association.rb +55 -36
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -8
  14. data/lib/active_record/associations/builder/association.rb +29 -38
  15. data/lib/active_record/associations/builder/belongs_to.rb +77 -30
  16. data/lib/active_record/associations/builder/collection_association.rb +14 -23
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +50 -39
  18. data/lib/active_record/associations/builder/has_many.rb +6 -4
  19. data/lib/active_record/associations/builder/has_one.rb +13 -6
  20. data/lib/active_record/associations/builder/singular_association.rb +15 -11
  21. data/lib/active_record/associations/collection_association.rb +145 -266
  22. data/lib/active_record/associations/collection_proxy.rb +242 -138
  23. data/lib/active_record/associations/foreign_association.rb +13 -0
  24. data/lib/active_record/associations/has_many_association.rb +35 -75
  25. data/lib/active_record/associations/has_many_through_association.rb +51 -69
  26. data/lib/active_record/associations/has_one_association.rb +39 -24
  27. data/lib/active_record/associations/has_one_through_association.rb +18 -9
  28. data/lib/active_record/associations/join_dependency/join_association.rb +40 -81
  29. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  30. data/lib/active_record/associations/join_dependency/join_part.rb +12 -12
  31. data/lib/active_record/associations/join_dependency.rb +134 -154
  32. data/lib/active_record/associations/preloader/association.rb +85 -116
  33. data/lib/active_record/associations/preloader/through_association.rb +85 -74
  34. data/lib/active_record/associations/preloader.rb +83 -93
  35. data/lib/active_record/associations/singular_association.rb +27 -40
  36. data/lib/active_record/associations/through_association.rb +48 -23
  37. data/lib/active_record/associations.rb +1732 -1596
  38. data/lib/active_record/attribute_assignment.rb +58 -182
  39. data/lib/active_record/attribute_decorators.rb +39 -15
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +12 -5
  41. data/lib/active_record/attribute_methods/dirty.rb +94 -125
  42. data/lib/active_record/attribute_methods/primary_key.rb +86 -71
  43. data/lib/active_record/attribute_methods/query.rb +4 -2
  44. data/lib/active_record/attribute_methods/read.rb +45 -63
  45. data/lib/active_record/attribute_methods/serialization.rb +40 -20
  46. data/lib/active_record/attribute_methods/time_zone_conversion.rb +62 -36
  47. data/lib/active_record/attribute_methods/write.rb +31 -46
  48. data/lib/active_record/attribute_methods.rb +170 -117
  49. data/lib/active_record/attributes.rb +201 -74
  50. data/lib/active_record/autosave_association.rb +118 -45
  51. data/lib/active_record/base.rb +60 -48
  52. data/lib/active_record/callbacks.rb +97 -57
  53. data/lib/active_record/coders/json.rb +3 -1
  54. data/lib/active_record/coders/yaml_column.rb +37 -13
  55. data/lib/active_record/collection_cache_key.rb +53 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +712 -284
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +10 -5
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +254 -87
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +72 -22
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -52
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +6 -4
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +67 -46
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +328 -217
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +81 -36
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +617 -212
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +139 -75
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +332 -191
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +567 -563
  69. data/lib/active_record/connection_adapters/column.rb +50 -41
  70. data/lib/active_record/connection_adapters/connection_specification.rb +147 -135
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +33 -0
  72. data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +140 -0
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +72 -0
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -0
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +73 -0
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +87 -0
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +80 -0
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +148 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +35 -0
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +42 -195
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +35 -11
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +46 -115
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +50 -57
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +10 -6
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +5 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +5 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +9 -13
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +7 -3
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -19
  95. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
  97. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
  99. data/lib/active_record/connection_adapters/postgresql/oid/{integer.rb → oid.rb} +6 -2
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +33 -11
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -34
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +65 -51
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +5 -3
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +23 -25
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +107 -47
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +65 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +144 -90
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +466 -280
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +39 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +12 -8
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +439 -330
  117. data/lib/active_record/connection_adapters/schema_cache.rb +48 -24
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +34 -0
  119. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
  120. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +67 -0
  121. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
  122. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  123. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +106 -0
  125. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +269 -324
  126. data/lib/active_record/connection_adapters/statement_pool.rb +34 -13
  127. data/lib/active_record/connection_handling.rb +40 -27
  128. data/lib/active_record/core.rb +205 -202
  129. data/lib/active_record/counter_cache.rb +80 -37
  130. data/lib/active_record/define_callbacks.rb +22 -0
  131. data/lib/active_record/dynamic_matchers.rb +87 -105
  132. data/lib/active_record/enum.rb +136 -90
  133. data/lib/active_record/errors.rb +180 -52
  134. data/lib/active_record/explain.rb +23 -11
  135. data/lib/active_record/explain_registry.rb +4 -2
  136. data/lib/active_record/explain_subscriber.rb +11 -6
  137. data/lib/active_record/fixture_set/file.rb +35 -9
  138. data/lib/active_record/fixtures.rb +193 -135
  139. data/lib/active_record/gem_version.rb +5 -3
  140. data/lib/active_record/inheritance.rb +148 -112
  141. data/lib/active_record/integration.rb +70 -28
  142. data/lib/active_record/internal_metadata.rb +45 -0
  143. data/lib/active_record/legacy_yaml_adapter.rb +48 -0
  144. data/lib/active_record/locale/en.yml +3 -2
  145. data/lib/active_record/locking/optimistic.rb +92 -98
  146. data/lib/active_record/locking/pessimistic.rb +15 -3
  147. data/lib/active_record/log_subscriber.rb +95 -33
  148. data/lib/active_record/migration/command_recorder.rb +133 -90
  149. data/lib/active_record/migration/compatibility.rb +217 -0
  150. data/lib/active_record/migration/join_table.rb +8 -6
  151. data/lib/active_record/migration.rb +594 -267
  152. data/lib/active_record/model_schema.rb +292 -111
  153. data/lib/active_record/nested_attributes.rb +266 -214
  154. data/lib/active_record/no_touching.rb +8 -2
  155. data/lib/active_record/null_relation.rb +24 -37
  156. data/lib/active_record/persistence.rb +350 -119
  157. data/lib/active_record/query_cache.rb +13 -24
  158. data/lib/active_record/querying.rb +19 -17
  159. data/lib/active_record/railtie.rb +117 -35
  160. data/lib/active_record/railties/console_sandbox.rb +2 -0
  161. data/lib/active_record/railties/controller_runtime.rb +9 -3
  162. data/lib/active_record/railties/databases.rake +160 -174
  163. data/lib/active_record/readonly_attributes.rb +5 -4
  164. data/lib/active_record/reflection.rb +447 -288
  165. data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
  166. data/lib/active_record/relation/batches.rb +204 -55
  167. data/lib/active_record/relation/calculations.rb +259 -244
  168. data/lib/active_record/relation/delegation.rb +67 -60
  169. data/lib/active_record/relation/finder_methods.rb +290 -253
  170. data/lib/active_record/relation/from_clause.rb +26 -0
  171. data/lib/active_record/relation/merger.rb +91 -68
  172. data/lib/active_record/relation/predicate_builder/array_handler.rb +24 -23
  173. data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
  174. data/lib/active_record/relation/predicate_builder/base_handler.rb +19 -0
  175. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +20 -0
  176. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
  177. data/lib/active_record/relation/predicate_builder/range_handler.rb +42 -0
  178. data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
  179. data/lib/active_record/relation/predicate_builder.rb +118 -92
  180. data/lib/active_record/relation/query_attribute.rb +45 -0
  181. data/lib/active_record/relation/query_methods.rb +446 -389
  182. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  183. data/lib/active_record/relation/spawn_methods.rb +18 -16
  184. data/lib/active_record/relation/where_clause.rb +186 -0
  185. data/lib/active_record/relation/where_clause_factory.rb +34 -0
  186. data/lib/active_record/relation.rb +287 -339
  187. data/lib/active_record/result.rb +54 -36
  188. data/lib/active_record/runtime_registry.rb +6 -4
  189. data/lib/active_record/sanitization.rb +155 -124
  190. data/lib/active_record/schema.rb +30 -24
  191. data/lib/active_record/schema_dumper.rb +91 -87
  192. data/lib/active_record/schema_migration.rb +19 -19
  193. data/lib/active_record/scoping/default.rb +102 -84
  194. data/lib/active_record/scoping/named.rb +81 -32
  195. data/lib/active_record/scoping.rb +45 -26
  196. data/lib/active_record/secure_token.rb +40 -0
  197. data/lib/active_record/serialization.rb +5 -5
  198. data/lib/active_record/statement_cache.rb +45 -35
  199. data/lib/active_record/store.rb +42 -36
  200. data/lib/active_record/suppressor.rb +61 -0
  201. data/lib/active_record/table_metadata.rb +82 -0
  202. data/lib/active_record/tasks/database_tasks.rb +136 -95
  203. data/lib/active_record/tasks/mysql_database_tasks.rb +59 -89
  204. data/lib/active_record/tasks/postgresql_database_tasks.rb +84 -31
  205. data/lib/active_record/tasks/sqlite_database_tasks.rb +44 -16
  206. data/lib/active_record/timestamp.rb +70 -38
  207. data/lib/active_record/touch_later.rb +64 -0
  208. data/lib/active_record/transactions.rb +208 -123
  209. data/lib/active_record/translation.rb +2 -0
  210. data/lib/active_record/type/adapter_specific_registry.rb +136 -0
  211. data/lib/active_record/type/date.rb +4 -41
  212. data/lib/active_record/type/date_time.rb +4 -38
  213. data/lib/active_record/type/decimal_without_scale.rb +6 -2
  214. data/lib/active_record/type/hash_lookup_type_map.rb +13 -5
  215. data/lib/active_record/type/internal/timezone.rb +17 -0
  216. data/lib/active_record/type/json.rb +30 -0
  217. data/lib/active_record/type/serialized.rb +30 -15
  218. data/lib/active_record/type/text.rb +2 -2
  219. data/lib/active_record/type/time.rb +11 -16
  220. data/lib/active_record/type/type_map.rb +15 -17
  221. data/lib/active_record/type/unsigned_integer.rb +9 -7
  222. data/lib/active_record/type.rb +79 -23
  223. data/lib/active_record/type_caster/connection.rb +33 -0
  224. data/lib/active_record/type_caster/map.rb +23 -0
  225. data/lib/active_record/type_caster.rb +9 -0
  226. data/lib/active_record/validations/absence.rb +25 -0
  227. data/lib/active_record/validations/associated.rb +13 -4
  228. data/lib/active_record/validations/length.rb +26 -0
  229. data/lib/active_record/validations/presence.rb +14 -13
  230. data/lib/active_record/validations/uniqueness.rb +41 -32
  231. data/lib/active_record/validations.rb +38 -35
  232. data/lib/active_record/version.rb +3 -1
  233. data/lib/active_record.rb +36 -21
  234. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
  235. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
  236. data/lib/rails/generators/active_record/migration/migration_generator.rb +43 -35
  237. data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +8 -6
  238. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +8 -7
  239. data/lib/rails/generators/active_record/migration.rb +18 -1
  240. data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
  241. data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +3 -0
  242. data/lib/rails/generators/active_record.rb +7 -5
  243. metadata +77 -53
  244. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  245. data/lib/active_record/associations/preloader/collection_association.rb +0 -24
  246. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  247. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  248. data/lib/active_record/associations/preloader/has_one.rb +0 -23
  249. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  250. data/lib/active_record/associations/preloader/singular_association.rb +0 -21
  251. data/lib/active_record/attribute.rb +0 -149
  252. data/lib/active_record/attribute_set/builder.rb +0 -86
  253. data/lib/active_record/attribute_set.rb +0 -77
  254. data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
  255. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
  256. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
  257. data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +0 -13
  258. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
  259. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
  260. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  261. data/lib/active_record/serializers/xml_serializer.rb +0 -193
  262. data/lib/active_record/type/big_integer.rb +0 -13
  263. data/lib/active_record/type/binary.rb +0 -50
  264. data/lib/active_record/type/boolean.rb +0 -30
  265. data/lib/active_record/type/decimal.rb +0 -40
  266. data/lib/active_record/type/decorator.rb +0 -14
  267. data/lib/active_record/type/float.rb +0 -19
  268. data/lib/active_record/type/integer.rb +0 -55
  269. data/lib/active_record/type/mutable.rb +0 -16
  270. data/lib/active_record/type/numeric.rb +0 -36
  271. data/lib/active_record/type/string.rb +0 -36
  272. data/lib/active_record/type/time_value.rb +0 -38
  273. data/lib/active_record/type/value.rb +0 -101
  274. /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
@@ -1,221 +1,235 @@
1
- require 'active_record'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
2
4
 
3
5
  db_namespace = namespace :db do
4
- task :load_config do
6
+ desc "Set the environment value for the database"
7
+ task "environment:set" => :load_config do
8
+ ActiveRecord::InternalMetadata.create_table
9
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Base.connection.migration_context.current_environment
10
+ end
11
+
12
+ task check_protected_environments: :load_config do
13
+ ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
14
+ end
15
+
16
+ task load_config: :environment do
5
17
  ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
6
18
  ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
7
19
  end
8
20
 
9
21
  namespace :create do
10
- task :all => :load_config do
22
+ task all: :load_config do
11
23
  ActiveRecord::Tasks::DatabaseTasks.create_all
12
24
  end
13
25
  end
14
26
 
15
- desc 'Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV it defaults to creating the development and test databases.'
16
- task :create => [:load_config] do
27
+ desc "Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases."
28
+ task create: [:load_config] do
17
29
  ActiveRecord::Tasks::DatabaseTasks.create_current
18
30
  end
19
31
 
20
32
  namespace :drop do
21
- task :all => :load_config do
33
+ task all: [:load_config, :check_protected_environments] do
22
34
  ActiveRecord::Tasks::DatabaseTasks.drop_all
23
35
  end
24
36
  end
25
37
 
26
- desc 'Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV it defaults to dropping the development and test databases.'
27
- task :drop => [:load_config] do
38
+ desc "Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases."
39
+ task drop: [:load_config, :check_protected_environments] do
40
+ db_namespace["drop:_unsafe"].invoke
41
+ end
42
+
43
+ task "drop:_unsafe" => [:load_config] do
28
44
  ActiveRecord::Tasks::DatabaseTasks.drop_current
29
45
  end
30
46
 
31
47
  namespace :purge do
32
- task :all => :load_config do
48
+ task all: [:load_config, :check_protected_environments] do
33
49
  ActiveRecord::Tasks::DatabaseTasks.purge_all
34
50
  end
35
51
  end
36
52
 
37
- # desc "Empty the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV it defaults to purging the development and test databases."
38
- task :purge => [:load_config] do
53
+ # desc "Empty the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:purge:all to purge all databases in the config). Without RAILS_ENV it defaults to purging the development and test databases."
54
+ task purge: [:load_config, :check_protected_environments] do
39
55
  ActiveRecord::Tasks::DatabaseTasks.purge_current
40
56
  end
41
57
 
42
58
  desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
43
- task :migrate => [:environment, :load_config] do
59
+ task migrate: :load_config do
44
60
  ActiveRecord::Tasks::DatabaseTasks.migrate
45
- db_namespace['_dump'].invoke if ActiveRecord::Base.dump_schema_after_migration
61
+ db_namespace["_dump"].invoke
46
62
  end
47
63
 
64
+ # IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
48
65
  task :_dump do
49
- case ActiveRecord::Base.schema_format
50
- when :ruby then db_namespace["schema:dump"].invoke
51
- when :sql then db_namespace["structure:dump"].invoke
52
- else
53
- raise "unknown schema format #{ActiveRecord::Base.schema_format}"
66
+ if ActiveRecord::Base.dump_schema_after_migration
67
+ case ActiveRecord::Base.schema_format
68
+ when :ruby then db_namespace["schema:dump"].invoke
69
+ when :sql then db_namespace["structure:dump"].invoke
70
+ else
71
+ raise "unknown schema format #{ActiveRecord::Base.schema_format}"
72
+ end
54
73
  end
55
74
  # Allow this task to be called as many times as required. An example is the
56
75
  # migrate:redo task, which calls other two internally that depend on this one.
57
- db_namespace['_dump'].reenable
76
+ db_namespace["_dump"].reenable
58
77
  end
59
78
 
60
79
  namespace :migrate do
61
80
  # desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
62
- task :redo => [:environment, :load_config] do
63
- if ENV['VERSION']
64
- db_namespace['migrate:down'].invoke
65
- db_namespace['migrate:up'].invoke
81
+ task redo: :load_config do
82
+ raise "Empty VERSION provided" if ENV["VERSION"] && ENV["VERSION"].empty?
83
+
84
+ if ENV["VERSION"]
85
+ db_namespace["migrate:down"].invoke
86
+ db_namespace["migrate:up"].invoke
66
87
  else
67
- db_namespace['rollback'].invoke
68
- db_namespace['migrate'].invoke
88
+ db_namespace["rollback"].invoke
89
+ db_namespace["migrate"].invoke
69
90
  end
70
91
  end
71
92
 
72
93
  # desc 'Resets your database using your migrations for the current environment'
73
- task :reset => ['db:drop', 'db:create', 'db:migrate']
94
+ task reset: ["db:drop", "db:create", "db:migrate"]
74
95
 
75
96
  # desc 'Runs the "up" for a given migration VERSION.'
76
- task :up => [:environment, :load_config] do
77
- version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
78
- raise 'VERSION is required' unless version
79
- ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_paths, version)
80
- db_namespace['_dump'].invoke
97
+ task up: :load_config do
98
+ raise "VERSION is required" if !ENV["VERSION"] || ENV["VERSION"].empty?
99
+
100
+ ActiveRecord::Tasks::DatabaseTasks.check_target_version
101
+
102
+ ActiveRecord::Base.connection.migration_context.run(
103
+ :up,
104
+ ActiveRecord::Tasks::DatabaseTasks.target_version
105
+ )
106
+ db_namespace["_dump"].invoke
81
107
  end
82
108
 
83
109
  # desc 'Runs the "down" for a given migration VERSION.'
84
- task :down => [:environment, :load_config] do
85
- version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
86
- raise 'VERSION is required - To go down one migration, run db:rollback' unless version
87
- ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_paths, version)
88
- db_namespace['_dump'].invoke
110
+ task down: :load_config do
111
+ raise "VERSION is required - To go down one migration, use db:rollback" if !ENV["VERSION"] || ENV["VERSION"].empty?
112
+
113
+ ActiveRecord::Tasks::DatabaseTasks.check_target_version
114
+
115
+ ActiveRecord::Base.connection.migration_context.run(
116
+ :down,
117
+ ActiveRecord::Tasks::DatabaseTasks.target_version
118
+ )
119
+ db_namespace["_dump"].invoke
89
120
  end
90
121
 
91
- desc 'Display status of migrations'
92
- task :status => [:environment, :load_config] do
122
+ desc "Display status of migrations"
123
+ task status: :load_config do
93
124
  unless ActiveRecord::SchemaMigration.table_exists?
94
- abort 'Schema migrations table does not exist yet.'
125
+ abort "Schema migrations table does not exist yet."
95
126
  end
96
- db_list = ActiveRecord::SchemaMigration.normalized_versions
97
-
98
- file_list =
99
- ActiveRecord::Migrator.migrations_paths.flat_map do |path|
100
- # match "20091231235959_some_name.rb" and "001_some_name.rb" pattern
101
- Dir.foreach(path).grep(/^(\d{3,})_(.+)\.rb$/) do
102
- version = ActiveRecord::SchemaMigration.normalize_migration_number($1)
103
- status = db_list.delete(version) ? 'up' : 'down'
104
- [status, version, $2.humanize]
105
- end
106
- end
107
127
 
108
- db_list.map! do |version|
109
- ['up', version, '********** NO FILE **********']
110
- end
111
128
  # output
112
129
  puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
113
130
  puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
114
131
  puts "-" * 50
115
- (db_list + file_list).sort_by { |_, version, _| version }.each do |status, version, name|
132
+ ActiveRecord::Base.connection.migration_context.migrations_status.each do |status, version, name|
116
133
  puts "#{status.center(8)} #{version.ljust(14)} #{name}"
117
134
  end
118
135
  puts
119
136
  end
120
137
  end
121
138
 
122
- desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
123
- task :rollback => [:environment, :load_config] do
124
- step = ENV['STEP'] ? ENV['STEP'].to_i : 1
125
- ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
126
- db_namespace['_dump'].invoke
139
+ desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
140
+ task rollback: :load_config do
141
+ step = ENV["STEP"] ? ENV["STEP"].to_i : 1
142
+ ActiveRecord::Base.connection.migration_context.rollback(step)
143
+ db_namespace["_dump"].invoke
127
144
  end
128
145
 
129
146
  # desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
130
- task :forward => [:environment, :load_config] do
131
- step = ENV['STEP'] ? ENV['STEP'].to_i : 1
132
- ActiveRecord::Migrator.forward(ActiveRecord::Migrator.migrations_paths, step)
133
- db_namespace['_dump'].invoke
147
+ task forward: :load_config do
148
+ step = ENV["STEP"] ? ENV["STEP"].to_i : 1
149
+ ActiveRecord::Base.connection.migration_context.forward(step)
150
+ db_namespace["_dump"].invoke
134
151
  end
135
152
 
136
153
  # desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
137
- task :reset => [:environment, :load_config] do
138
- db_namespace["drop"].invoke
139
- db_namespace["setup"].invoke
140
- end
154
+ task reset: [ "db:drop", "db:setup" ]
141
155
 
142
156
  # desc "Retrieves the charset for the current environment's database"
143
- task :charset => [:environment, :load_config] do
157
+ task charset: :load_config do
144
158
  puts ActiveRecord::Tasks::DatabaseTasks.charset_current
145
159
  end
146
160
 
147
161
  # desc "Retrieves the collation for the current environment's database"
148
- task :collation => [:environment, :load_config] do
162
+ task collation: :load_config do
149
163
  begin
150
164
  puts ActiveRecord::Tasks::DatabaseTasks.collation_current
151
165
  rescue NoMethodError
152
- $stderr.puts 'Sorry, your database adapter is not supported yet. Feel free to submit a patch.'
166
+ $stderr.puts "Sorry, your database adapter is not supported yet. Feel free to submit a patch."
153
167
  end
154
168
  end
155
169
 
156
- desc 'Retrieves the current schema version number'
157
- task :version => [:environment, :load_config] do
158
- puts "Current version: #{ActiveRecord::Migrator.current_version}"
170
+ desc "Retrieves the current schema version number"
171
+ task version: :load_config do
172
+ puts "Current version: #{ActiveRecord::Base.connection.migration_context.current_version}"
159
173
  end
160
174
 
161
175
  # desc "Raises an error if there are pending migrations"
162
- task :abort_if_pending_migrations => :environment do
163
- pending_migrations = ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations
176
+ task abort_if_pending_migrations: :load_config do
177
+ pending_migrations = ActiveRecord::Base.connection.migration_context.open.pending_migrations
164
178
 
165
179
  if pending_migrations.any?
166
180
  puts "You have #{pending_migrations.size} pending #{pending_migrations.size > 1 ? 'migrations:' : 'migration:'}"
167
181
  pending_migrations.each do |pending_migration|
168
- puts ' %4d %s' % [pending_migration.version, pending_migration.name]
182
+ puts " %4d %s" % [pending_migration.version, pending_migration.name]
169
183
  end
170
- abort %{Run `rake db:migrate` to update your database then try again.}
184
+ abort %{Run `rails db:migrate` to update your database then try again.}
171
185
  end
172
186
  end
173
187
 
174
- desc 'Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)'
175
- task :setup => ['db:schema:load_if_ruby', 'db:structure:load_if_sql', :seed]
188
+ desc "Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)"
189
+ task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed]
176
190
 
177
- desc 'Load the seed data from db/seeds.rb'
191
+ desc "Loads the seed data from db/seeds.rb"
178
192
  task :seed do
179
- db_namespace['abort_if_pending_migrations'].invoke
193
+ db_namespace["abort_if_pending_migrations"].invoke
180
194
  ActiveRecord::Tasks::DatabaseTasks.load_seed
181
195
  end
182
196
 
183
197
  namespace :fixtures do
184
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
185
- task :load => [:environment, :load_config] do
186
- require 'active_record/fixtures'
198
+ desc "Loads fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
199
+ task load: :load_config do
200
+ require "active_record/fixtures"
187
201
 
188
202
  base_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
189
203
 
190
- fixtures_dir = if ENV['FIXTURES_DIR']
191
- File.join base_dir, ENV['FIXTURES_DIR']
192
- else
193
- base_dir
194
- end
204
+ fixtures_dir = if ENV["FIXTURES_DIR"]
205
+ File.join base_dir, ENV["FIXTURES_DIR"]
206
+ else
207
+ base_dir
208
+ end
195
209
 
196
- fixture_files = if ENV['FIXTURES']
197
- ENV['FIXTURES'].split(',')
198
- else
199
- # The use of String#[] here is to support namespaced fixtures
200
- Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }
201
- end
210
+ fixture_files = if ENV["FIXTURES"]
211
+ ENV["FIXTURES"].split(",")
212
+ else
213
+ # The use of String#[] here is to support namespaced fixtures.
214
+ Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] }
215
+ end
202
216
 
203
217
  ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
204
218
  end
205
219
 
206
220
  # desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
207
- task :identify => [:environment, :load_config] do
208
- require 'active_record/fixtures'
221
+ task identify: :load_config do
222
+ require "active_record/fixtures"
209
223
 
210
- label, id = ENV['LABEL'], ENV['ID']
211
- raise 'LABEL or ID required' if label.blank? && id.blank?
224
+ label, id = ENV["LABEL"], ENV["ID"]
225
+ raise "LABEL or ID required" if label.blank? && id.blank?
212
226
 
213
227
  puts %Q(The fixture ID for "#{label}" is #{ActiveRecord::FixtureSet.identify(label)}.) if label
214
228
 
215
229
  base_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
216
230
 
217
231
  Dir["#{base_dir}/**/*.yml"].each do |file|
218
- if data = YAML::load(ERB.new(IO.read(file)).result)
232
+ if data = YAML.load(ERB.new(IO.read(file)).result)
219
233
  data.each_key do |key|
220
234
  key_id = ActiveRecord::FixtureSet.identify(key)
221
235
 
@@ -229,97 +243,85 @@ db_namespace = namespace :db do
229
243
  end
230
244
 
231
245
  namespace :schema do
232
- desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
233
- task :dump => [:environment, :load_config] do
234
- require 'active_record/schema_dumper'
235
- filename = ENV['SCHEMA'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema.rb')
246
+ desc "Creates a db/schema.rb file that is portable against any DB supported by Active Record"
247
+ task dump: :load_config do
248
+ require "active_record/schema_dumper"
249
+ filename = ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema.rb")
236
250
  File.open(filename, "w:utf-8") do |file|
237
251
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
238
252
  end
239
- db_namespace['schema:dump'].reenable
253
+ db_namespace["schema:dump"].reenable
240
254
  end
241
255
 
242
- desc 'Load a schema.rb file into the database'
243
- task :load => [:environment, :load_config] do
244
- ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA'])
256
+ desc "Loads a schema.rb file into the database"
257
+ task load: [:load_config, :check_protected_environments] do
258
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV["SCHEMA"])
245
259
  end
246
260
 
247
- task :load_if_ruby => ['db:create', :environment] do
261
+ task load_if_ruby: ["db:create", :environment] do
248
262
  db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby
249
263
  end
250
264
 
251
265
  namespace :cache do
252
- desc 'Create a db/schema_cache.dump file.'
253
- task :dump => [:environment, :load_config] do
254
- con = ActiveRecord::Base.connection
255
- filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.dump")
256
-
257
- con.schema_cache.clear!
258
- con.tables.each { |table| con.schema_cache.add(table) }
259
- open(filename, 'wb') { |f| f.write(Marshal.dump(con.schema_cache)) }
266
+ desc "Creates a db/schema_cache.yml file."
267
+ task dump: :load_config do
268
+ conn = ActiveRecord::Base.connection
269
+ filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.yml")
270
+ ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache(conn, filename)
260
271
  end
261
272
 
262
- desc 'Clear a db/schema_cache.dump file.'
263
- task :clear => [:environment, :load_config] do
264
- filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.dump")
265
- FileUtils.rm(filename) if File.exist?(filename)
273
+ desc "Clears a db/schema_cache.yml file."
274
+ task clear: :load_config do
275
+ filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.yml")
276
+ rm_f filename, verbose: false
266
277
  end
267
278
  end
268
279
 
269
280
  end
270
281
 
271
282
  namespace :structure do
272
- desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
273
- task :dump => [:environment, :load_config] do
274
- filename = ENV['DB_STRUCTURE'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure.sql")
283
+ desc "Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
284
+ task dump: :load_config do
285
+ filename = ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure.sql")
275
286
  current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
276
287
  ActiveRecord::Tasks::DatabaseTasks.structure_dump(current_config, filename)
277
288
 
278
- if ActiveRecord::Base.connection.supports_migrations? &&
279
- ActiveRecord::SchemaMigration.table_exists?
289
+ if ActiveRecord::SchemaMigration.table_exists?
280
290
  File.open(filename, "a") do |f|
281
291
  f.puts ActiveRecord::Base.connection.dump_schema_information
282
292
  f.print "\n"
283
293
  end
284
294
  end
285
- db_namespace['structure:dump'].reenable
295
+ db_namespace["structure:dump"].reenable
286
296
  end
287
297
 
288
- desc "Recreate the databases from the structure.sql file"
289
- task :load => [:environment, :load_config] do
290
- ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:sql, ENV['DB_STRUCTURE'])
298
+ desc "Recreates the databases from the structure.sql file"
299
+ task load: [:load_config, :check_protected_environments] do
300
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:sql, ENV["SCHEMA"])
291
301
  end
292
302
 
293
- task :load_if_sql => ['db:create', :environment] do
303
+ task load_if_sql: ["db:create", :environment] do
294
304
  db_namespace["structure:load"].invoke if ActiveRecord::Base.schema_format == :sql
295
305
  end
296
306
  end
297
307
 
298
308
  namespace :test do
299
-
300
- task :deprecated do
301
- Rake.application.top_level_tasks.grep(/^db:test:/).each do |task|
302
- $stderr.puts "WARNING: #{task} is deprecated. The Rails test helper now maintains " \
303
- "your test schema automatically, see the release notes for details."
304
- end
305
- end
306
-
307
309
  # desc "Recreate the test database from the current schema"
308
- task :load => %w(db:test:purge) do
310
+ task load: %w(db:test:purge) do
309
311
  case ActiveRecord::Base.schema_format
310
- when :ruby
311
- db_namespace["test:load_schema"].invoke
312
- when :sql
313
- db_namespace["test:load_structure"].invoke
312
+ when :ruby
313
+ db_namespace["test:load_schema"].invoke
314
+ when :sql
315
+ db_namespace["test:load_structure"].invoke
314
316
  end
315
317
  end
316
318
 
317
319
  # desc "Recreate the test database from an existent schema.rb file"
318
- task :load_schema => %w(db:test:purge) do
320
+ task load_schema: %w(db:test:purge) do
319
321
  begin
320
322
  should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
321
323
  ActiveRecord::Schema.verbose = false
322
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
324
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations["test"], :ruby, ENV["SCHEMA"], "test"
323
325
  ensure
324
326
  if should_reconnect
325
327
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
@@ -328,35 +330,19 @@ db_namespace = namespace :db do
328
330
  end
329
331
 
330
332
  # desc "Recreate the test database from an existent structure.sql file"
331
- task :load_structure => %w(db:test:purge) do
332
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
333
- end
334
-
335
- # desc "Recreate the test database from a fresh schema"
336
- task :clone => %w(db:test:deprecated environment) do
337
- case ActiveRecord::Base.schema_format
338
- when :ruby
339
- db_namespace["test:clone_schema"].invoke
340
- when :sql
341
- db_namespace["test:clone_structure"].invoke
342
- end
333
+ task load_structure: %w(db:test:purge) do
334
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations["test"], :sql, ENV["SCHEMA"], "test"
343
335
  end
344
336
 
345
- # desc "Recreate the test database from a fresh schema.rb file"
346
- task :clone_schema => %w(db:test:deprecated db:schema:dump db:test:load_schema)
347
-
348
- # desc "Recreate the test database from a fresh structure.sql file"
349
- task :clone_structure => %w(db:test:deprecated db:structure:dump db:test:load_structure)
350
-
351
337
  # desc "Empty the test database"
352
- task :purge => %w(environment load_config) do
353
- ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations['test']
338
+ task purge: %w(load_config check_protected_environments) do
339
+ ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations["test"]
354
340
  end
355
341
 
356
- # desc 'Check for pending migrations and load the test schema'
357
- task :prepare => %w(environment load_config) do
342
+ # desc 'Load the test schema'
343
+ task prepare: :load_config do
358
344
  unless ActiveRecord::Base.configurations.blank?
359
- db_namespace['test:load'].invoke
345
+ db_namespace["test:load"].invoke
360
346
  end
361
347
  end
362
348
  end
@@ -365,13 +351,13 @@ end
365
351
  namespace :railties do
366
352
  namespace :install do
367
353
  # desc "Copies missing migrations from Railties (e.g. engines). You can specify Railties to use with FROM=railtie1,railtie2"
368
- task :migrations => :'db:load_config' do
369
- to_load = ENV['FROM'].blank? ? :all : ENV['FROM'].split(",").map {|n| n.strip }
354
+ task migrations: :'db:load_config' do
355
+ to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map(&:strip)
370
356
  railties = {}
371
357
  Rails.application.migration_railties.each do |railtie|
372
358
  next unless to_load == :all || to_load.include?(railtie.railtie_name)
373
359
 
374
- if railtie.respond_to?(:paths) && (path = railtie.paths['db/migrate'].first)
360
+ if railtie.respond_to?(:paths) && (path = railtie.paths["db/migrate"].first)
375
361
  railties[railtie.railtie_name] = path
376
362
  end
377
363
  end
@@ -384,8 +370,8 @@ namespace :railties do
384
370
  puts "Copied migration #{migration.basename} from #{name}"
385
371
  end
386
372
 
387
- ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_paths.first, railties,
388
- :on_skip => on_skip, :on_copy => on_copy)
373
+ ActiveRecord::Migration.copy(ActiveRecord::Tasks::DatabaseTasks.migrations_paths.first, railties,
374
+ on_skip: on_skip, on_copy: on_copy)
389
375
  end
390
376
  end
391
377
  end
@@ -1,22 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ReadonlyAttributes
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  included do
6
- class_attribute :_attr_readonly, instance_accessor: false
7
- self._attr_readonly = []
8
+ class_attribute :_attr_readonly, instance_accessor: false, default: []
8
9
  end
9
10
 
10
11
  module ClassMethods
11
12
  # Attributes listed as readonly will be used to create a new record but update operations will
12
13
  # ignore these fields.
13
14
  def attr_readonly(*attributes)
14
- self._attr_readonly = Set.new(attributes.map { |a| a.to_s }) + (self._attr_readonly || [])
15
+ self._attr_readonly = Set.new(attributes.map(&:to_s)) + (_attr_readonly || [])
15
16
  end
16
17
 
17
18
  # Returns an array of all the attributes that have been specified as readonly.
18
19
  def readonly_attributes
19
- self._attr_readonly
20
+ _attr_readonly
20
21
  end
21
22
  end
22
23
  end