activerecord 6.1.6 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +1627 -983
 - data/MIT-LICENSE +1 -1
 - data/README.rdoc +18 -18
 - data/lib/active_record/aggregations.rb +17 -14
 - data/lib/active_record/association_relation.rb +1 -11
 - data/lib/active_record/associations/association.rb +50 -19
 - data/lib/active_record/associations/association_scope.rb +17 -12
 - data/lib/active_record/associations/belongs_to_association.rb +28 -9
 - data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
 - data/lib/active_record/associations/builder/association.rb +11 -5
 - data/lib/active_record/associations/builder/belongs_to.rb +40 -14
 - data/lib/active_record/associations/builder/collection_association.rb +10 -3
 - data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -5
 - data/lib/active_record/associations/builder/has_many.rb +3 -2
 - data/lib/active_record/associations/builder/has_one.rb +2 -1
 - data/lib/active_record/associations/builder/singular_association.rb +6 -2
 - data/lib/active_record/associations/collection_association.rb +35 -31
 - data/lib/active_record/associations/collection_proxy.rb +30 -15
 - data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
 - data/lib/active_record/associations/foreign_association.rb +10 -3
 - data/lib/active_record/associations/has_many_association.rb +28 -18
 - data/lib/active_record/associations/has_many_through_association.rb +12 -7
 - data/lib/active_record/associations/has_one_association.rb +20 -10
 - data/lib/active_record/associations/has_one_through_association.rb +1 -1
 - data/lib/active_record/associations/join_dependency.rb +26 -16
 - data/lib/active_record/associations/preloader/association.rb +207 -52
 - data/lib/active_record/associations/preloader/batch.rb +48 -0
 - data/lib/active_record/associations/preloader/branch.rb +147 -0
 - data/lib/active_record/associations/preloader/through_association.rb +50 -14
 - data/lib/active_record/associations/preloader.rb +50 -121
 - data/lib/active_record/associations/singular_association.rb +9 -3
 - data/lib/active_record/associations/through_association.rb +25 -14
 - data/lib/active_record/associations.rb +439 -305
 - data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
 - data/lib/active_record/attribute_assignment.rb +1 -3
 - data/lib/active_record/attribute_methods/before_type_cast.rb +24 -2
 - data/lib/active_record/attribute_methods/dirty.rb +73 -22
 - data/lib/active_record/attribute_methods/primary_key.rb +78 -26
 - data/lib/active_record/attribute_methods/query.rb +31 -19
 - data/lib/active_record/attribute_methods/read.rb +25 -10
 - data/lib/active_record/attribute_methods/serialization.rb +194 -37
 - data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
 - data/lib/active_record/attribute_methods/write.rb +10 -13
 - data/lib/active_record/attribute_methods.rb +121 -40
 - data/lib/active_record/attributes.rb +27 -38
 - data/lib/active_record/autosave_association.rb +61 -30
 - data/lib/active_record/base.rb +25 -2
 - data/lib/active_record/callbacks.rb +18 -34
 - data/lib/active_record/coders/column_serializer.rb +61 -0
 - data/lib/active_record/coders/json.rb +1 -1
 - data/lib/active_record/coders/yaml_column.rb +70 -34
 - data/lib/active_record/connection_adapters/abstract/connection_handler.rb +367 -0
 - data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +211 -0
 - data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +78 -0
 - data/lib/active_record/connection_adapters/abstract/connection_pool.rb +96 -590
 - data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -17
 - data/lib/active_record/connection_adapters/abstract/database_statements.rb +172 -50
 - data/lib/active_record/connection_adapters/abstract/query_cache.rb +77 -27
 - data/lib/active_record/connection_adapters/abstract/quoting.rb +87 -73
 - data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
 - data/lib/active_record/connection_adapters/abstract/schema_creation.rb +21 -20
 - data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +186 -31
 - data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
 - data/lib/active_record/connection_adapters/abstract/schema_statements.rb +360 -138
 - data/lib/active_record/connection_adapters/abstract/transaction.rb +281 -59
 - data/lib/active_record/connection_adapters/abstract_adapter.rb +631 -149
 - data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +285 -156
 - data/lib/active_record/connection_adapters/column.rb +13 -0
 - data/lib/active_record/connection_adapters/mysql/column.rb +1 -0
 - data/lib/active_record/connection_adapters/mysql/database_statements.rb +25 -134
 - data/lib/active_record/connection_adapters/mysql/quoting.rb +56 -25
 - data/lib/active_record/connection_adapters/mysql/schema_creation.rb +9 -0
 - data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +10 -1
 - data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -2
 - data/lib/active_record/connection_adapters/mysql/schema_statements.rb +38 -14
 - data/lib/active_record/connection_adapters/mysql2/database_statements.rb +151 -0
 - data/lib/active_record/connection_adapters/mysql2_adapter.rb +104 -53
 - data/lib/active_record/connection_adapters/pool_config.rb +20 -11
 - data/lib/active_record/connection_adapters/pool_manager.rb +19 -9
 - data/lib/active_record/connection_adapters/postgresql/column.rb +30 -1
 - data/lib/active_record/connection_adapters/postgresql/database_statements.rb +89 -52
 - data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
 - data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
 - data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
 - data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
 - data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -2
 - data/lib/active_record/connection_adapters/postgresql/oid/range.rb +12 -3
 - data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
 - data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
 - data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
 - data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
 - data/lib/active_record/connection_adapters/postgresql/quoting.rb +89 -56
 - data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +28 -0
 - data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +92 -2
 - data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +153 -3
 - data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -0
 - data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +394 -74
 - data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
 - data/lib/active_record/connection_adapters/postgresql_adapter.rb +509 -247
 - data/lib/active_record/connection_adapters/schema_cache.rb +319 -90
 - data/lib/active_record/connection_adapters/sqlite3/column.rb +49 -0
 - data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +72 -53
 - data/lib/active_record/connection_adapters/sqlite3/quoting.rb +37 -21
 - data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +7 -0
 - data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +43 -22
 - data/lib/active_record/connection_adapters/sqlite3_adapter.rb +294 -102
 - data/lib/active_record/connection_adapters/statement_pool.rb +7 -0
 - data/lib/active_record/connection_adapters/trilogy/database_statements.rb +99 -0
 - data/lib/active_record/connection_adapters/trilogy_adapter.rb +254 -0
 - data/lib/active_record/connection_adapters.rb +9 -6
 - data/lib/active_record/connection_handling.rb +107 -136
 - data/lib/active_record/core.rb +202 -223
 - data/lib/active_record/counter_cache.rb +46 -25
 - data/lib/active_record/database_configurations/connection_url_resolver.rb +2 -1
 - data/lib/active_record/database_configurations/database_config.rb +21 -12
 - data/lib/active_record/database_configurations/hash_config.rb +84 -16
 - data/lib/active_record/database_configurations/url_config.rb +18 -12
 - data/lib/active_record/database_configurations.rb +95 -59
 - data/lib/active_record/delegated_type.rb +61 -15
 - data/lib/active_record/deprecator.rb +7 -0
 - data/lib/active_record/destroy_association_async_job.rb +3 -1
 - data/lib/active_record/disable_joins_association_relation.rb +39 -0
 - data/lib/active_record/dynamic_matchers.rb +1 -1
 - data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
 - data/lib/active_record/encryption/cipher/aes256_gcm.rb +101 -0
 - data/lib/active_record/encryption/cipher.rb +53 -0
 - data/lib/active_record/encryption/config.rb +68 -0
 - data/lib/active_record/encryption/configurable.rb +60 -0
 - data/lib/active_record/encryption/context.rb +42 -0
 - data/lib/active_record/encryption/contexts.rb +76 -0
 - data/lib/active_record/encryption/derived_secret_key_provider.rb +18 -0
 - data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
 - data/lib/active_record/encryption/encryptable_record.rb +224 -0
 - data/lib/active_record/encryption/encrypted_attribute_type.rb +151 -0
 - data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
 - data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
 - data/lib/active_record/encryption/encryptor.rb +155 -0
 - data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
 - data/lib/active_record/encryption/errors.rb +15 -0
 - data/lib/active_record/encryption/extended_deterministic_queries.rb +157 -0
 - data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
 - data/lib/active_record/encryption/key.rb +28 -0
 - data/lib/active_record/encryption/key_generator.rb +53 -0
 - data/lib/active_record/encryption/key_provider.rb +46 -0
 - data/lib/active_record/encryption/message.rb +33 -0
 - data/lib/active_record/encryption/message_serializer.rb +92 -0
 - data/lib/active_record/encryption/null_encryptor.rb +21 -0
 - data/lib/active_record/encryption/properties.rb +76 -0
 - data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
 - data/lib/active_record/encryption/scheme.rb +96 -0
 - data/lib/active_record/encryption.rb +56 -0
 - data/lib/active_record/enum.rb +154 -63
 - data/lib/active_record/errors.rb +171 -15
 - data/lib/active_record/explain.rb +23 -3
 - data/lib/active_record/explain_registry.rb +11 -6
 - data/lib/active_record/explain_subscriber.rb +1 -1
 - data/lib/active_record/fixture_set/file.rb +15 -1
 - data/lib/active_record/fixture_set/model_metadata.rb +14 -4
 - data/lib/active_record/fixture_set/render_context.rb +2 -0
 - data/lib/active_record/fixture_set/table_row.rb +70 -14
 - data/lib/active_record/fixture_set/table_rows.rb +4 -4
 - data/lib/active_record/fixtures.rb +131 -86
 - data/lib/active_record/future_result.rb +164 -0
 - data/lib/active_record/gem_version.rb +3 -3
 - data/lib/active_record/inheritance.rb +81 -29
 - data/lib/active_record/insert_all.rb +135 -22
 - data/lib/active_record/integration.rb +11 -10
 - data/lib/active_record/internal_metadata.rb +119 -33
 - data/lib/active_record/legacy_yaml_adapter.rb +2 -39
 - data/lib/active_record/locking/optimistic.rb +36 -21
 - data/lib/active_record/locking/pessimistic.rb +15 -6
 - data/lib/active_record/log_subscriber.rb +52 -19
 - data/lib/active_record/marshalling.rb +56 -0
 - data/lib/active_record/message_pack.rb +124 -0
 - data/lib/active_record/middleware/database_selector/resolver.rb +10 -10
 - data/lib/active_record/middleware/database_selector.rb +23 -13
 - data/lib/active_record/middleware/shard_selector.rb +62 -0
 - data/lib/active_record/migration/command_recorder.rb +112 -14
 - data/lib/active_record/migration/compatibility.rb +221 -48
 - data/lib/active_record/migration/default_strategy.rb +23 -0
 - data/lib/active_record/migration/execution_strategy.rb +19 -0
 - data/lib/active_record/migration/join_table.rb +1 -1
 - data/lib/active_record/migration/pending_migration_connection.rb +21 -0
 - data/lib/active_record/migration.rb +358 -171
 - data/lib/active_record/model_schema.rb +120 -101
 - data/lib/active_record/nested_attributes.rb +37 -18
 - data/lib/active_record/no_touching.rb +3 -3
 - data/lib/active_record/normalization.rb +167 -0
 - data/lib/active_record/persistence.rb +405 -85
 - data/lib/active_record/promise.rb +84 -0
 - data/lib/active_record/query_cache.rb +3 -21
 - data/lib/active_record/query_logs.rb +174 -0
 - data/lib/active_record/query_logs_formatter.rb +41 -0
 - data/lib/active_record/querying.rb +29 -6
 - data/lib/active_record/railtie.rb +219 -43
 - data/lib/active_record/railties/controller_runtime.rb +13 -9
 - data/lib/active_record/railties/databases.rake +188 -252
 - data/lib/active_record/railties/job_runtime.rb +23 -0
 - data/lib/active_record/readonly_attributes.rb +41 -3
 - data/lib/active_record/reflection.rb +241 -80
 - data/lib/active_record/relation/batches/batch_enumerator.rb +23 -7
 - data/lib/active_record/relation/batches.rb +192 -63
 - data/lib/active_record/relation/calculations.rb +219 -90
 - data/lib/active_record/relation/delegation.rb +27 -13
 - data/lib/active_record/relation/finder_methods.rb +108 -51
 - data/lib/active_record/relation/merger.rb +22 -13
 - data/lib/active_record/relation/predicate_builder/association_query_value.rb +31 -3
 - data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +4 -6
 - data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
 - data/lib/active_record/relation/predicate_builder.rb +27 -20
 - data/lib/active_record/relation/query_attribute.rb +30 -12
 - data/lib/active_record/relation/query_methods.rb +654 -127
 - data/lib/active_record/relation/record_fetch_warning.rb +7 -9
 - data/lib/active_record/relation/spawn_methods.rb +20 -3
 - data/lib/active_record/relation/where_clause.rb +10 -19
 - data/lib/active_record/relation.rb +262 -120
 - data/lib/active_record/result.rb +37 -11
 - data/lib/active_record/runtime_registry.rb +18 -13
 - data/lib/active_record/sanitization.rb +65 -20
 - data/lib/active_record/schema.rb +36 -22
 - data/lib/active_record/schema_dumper.rb +73 -24
 - data/lib/active_record/schema_migration.rb +68 -33
 - data/lib/active_record/scoping/default.rb +72 -15
 - data/lib/active_record/scoping/named.rb +5 -13
 - data/lib/active_record/scoping.rb +65 -34
 - data/lib/active_record/secure_password.rb +60 -0
 - data/lib/active_record/secure_token.rb +21 -3
 - data/lib/active_record/serialization.rb +6 -1
 - data/lib/active_record/signed_id.rb +10 -8
 - data/lib/active_record/store.rb +16 -11
 - data/lib/active_record/suppressor.rb +13 -15
 - data/lib/active_record/table_metadata.rb +16 -3
 - data/lib/active_record/tasks/database_tasks.rb +225 -136
 - data/lib/active_record/tasks/mysql_database_tasks.rb +16 -7
 - data/lib/active_record/tasks/postgresql_database_tasks.rb +35 -26
 - data/lib/active_record/tasks/sqlite_database_tasks.rb +15 -7
 - data/lib/active_record/test_databases.rb +1 -1
 - data/lib/active_record/test_fixtures.rb +123 -99
 - data/lib/active_record/timestamp.rb +29 -18
 - data/lib/active_record/token_for.rb +113 -0
 - data/lib/active_record/touch_later.rb +11 -6
 - data/lib/active_record/transactions.rb +48 -27
 - data/lib/active_record/translation.rb +3 -3
 - data/lib/active_record/type/adapter_specific_registry.rb +32 -14
 - data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
 - data/lib/active_record/type/internal/timezone.rb +7 -2
 - data/lib/active_record/type/serialized.rb +9 -5
 - data/lib/active_record/type/time.rb +4 -0
 - data/lib/active_record/type/type_map.rb +17 -20
 - data/lib/active_record/type.rb +1 -2
 - data/lib/active_record/validations/absence.rb +1 -1
 - data/lib/active_record/validations/associated.rb +4 -4
 - data/lib/active_record/validations/numericality.rb +5 -4
 - data/lib/active_record/validations/presence.rb +5 -28
 - data/lib/active_record/validations/uniqueness.rb +51 -6
 - data/lib/active_record/validations.rb +8 -4
 - data/lib/active_record/version.rb +1 -1
 - data/lib/active_record.rb +335 -32
 - data/lib/arel/attributes/attribute.rb +0 -8
 - data/lib/arel/crud.rb +28 -22
 - data/lib/arel/delete_manager.rb +18 -4
 - data/lib/arel/errors.rb +10 -0
 - data/lib/arel/factory_methods.rb +4 -0
 - data/lib/arel/filter_predications.rb +9 -0
 - data/lib/arel/insert_manager.rb +2 -3
 - data/lib/arel/nodes/and.rb +4 -0
 - data/lib/arel/nodes/binary.rb +6 -1
 - data/lib/arel/nodes/bound_sql_literal.rb +61 -0
 - data/lib/arel/nodes/casted.rb +1 -1
 - data/lib/arel/nodes/cte.rb +36 -0
 - data/lib/arel/nodes/delete_statement.rb +12 -13
 - data/lib/arel/nodes/filter.rb +10 -0
 - data/lib/arel/nodes/fragments.rb +35 -0
 - data/lib/arel/nodes/function.rb +1 -0
 - data/lib/arel/nodes/homogeneous_in.rb +1 -9
 - data/lib/arel/nodes/insert_statement.rb +2 -2
 - data/lib/arel/nodes/leading_join.rb +8 -0
 - data/lib/arel/nodes/node.rb +111 -2
 - data/lib/arel/nodes/select_core.rb +2 -2
 - data/lib/arel/nodes/select_statement.rb +2 -2
 - data/lib/arel/nodes/sql_literal.rb +6 -0
 - data/lib/arel/nodes/table_alias.rb +4 -0
 - data/lib/arel/nodes/update_statement.rb +8 -3
 - data/lib/arel/nodes.rb +5 -0
 - data/lib/arel/predications.rb +13 -3
 - data/lib/arel/select_manager.rb +10 -4
 - data/lib/arel/table.rb +9 -6
 - data/lib/arel/tree_manager.rb +0 -12
 - data/lib/arel/update_manager.rb +18 -4
 - data/lib/arel/visitors/dot.rb +80 -90
 - data/lib/arel/visitors/mysql.rb +16 -3
 - data/lib/arel/visitors/postgresql.rb +0 -10
 - data/lib/arel/visitors/to_sql.rb +139 -19
 - data/lib/arel/visitors/visitor.rb +2 -2
 - data/lib/arel.rb +18 -3
 - data/lib/rails/generators/active_record/application_record/USAGE +8 -0
 - data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
 - data/lib/rails/generators/active_record/migration.rb +3 -1
 - data/lib/rails/generators/active_record/model/USAGE +113 -0
 - data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
 - data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
 - data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
 - data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
 - data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
 - data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
 - metadata +93 -13
 - data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
 - data/lib/active_record/null_relation.rb +0 -67
 
| 
         @@ -10,11 +10,8 @@ module ActiveRecord 
     | 
|
| 
       10 
10 
     | 
    
         
             
                included do
         
     | 
| 
       11 
11 
     | 
    
         
             
                  class_attribute :attributes_to_define_after_schema_loads, instance_accessor: false, default: {} # :internal:
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                # = Active Record \Attributes
         
     | 
| 
       14 
14 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       15 
     | 
    
         
            -
                  ##
         
     | 
| 
       16 
     | 
    
         
            -
                  # :call-seq: attribute(name, cast_type = nil, **options)
         
     | 
| 
       17 
     | 
    
         
            -
                  #
         
     | 
| 
       18 
15 
     | 
    
         
             
                  # Defines an attribute with a type on this model. It will override the
         
     | 
| 
       19 
16 
     | 
    
         
             
                  # type of existing attributes if needed. This allows control over how
         
     | 
| 
       20 
17 
     | 
    
         
             
                  # values are converted to and from SQL when assigned to a model. It also
         
     | 
| 
         @@ -197,10 +194,10 @@ module ActiveRecord 
     | 
|
| 
       197 
194 
     | 
    
         
             
                  #   end
         
     | 
| 
       198 
195 
     | 
    
         
             
                  #
         
     | 
| 
       199 
196 
     | 
    
         
             
                  #   Product.where(price_in_bitcoins: Money.new(5, "USD"))
         
     | 
| 
       200 
     | 
    
         
            -
                  #   #  
     | 
| 
      
 197 
     | 
    
         
            +
                  #   # SELECT * FROM products WHERE price_in_bitcoins = 0.02230
         
     | 
| 
       201 
198 
     | 
    
         
             
                  #
         
     | 
| 
       202 
199 
     | 
    
         
             
                  #   Product.where(price_in_bitcoins: Money.new(5, "GBP"))
         
     | 
| 
       203 
     | 
    
         
            -
                  #   #  
     | 
| 
      
 200 
     | 
    
         
            +
                  #   # SELECT * FROM products WHERE price_in_bitcoins = 0.03412
         
     | 
| 
       204 
201 
     | 
    
         
             
                  #
         
     | 
| 
       205 
202 
     | 
    
         
             
                  # ==== Dirty Tracking
         
     | 
| 
       206 
203 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -208,14 +205,31 @@ module ActiveRecord 
     | 
|
| 
       208 
205 
     | 
    
         
             
                  # tracking is performed. The methods +changed?+ and +changed_in_place?+
         
     | 
| 
       209 
206 
     | 
    
         
             
                  # will be called from ActiveModel::Dirty. See the documentation for those
         
     | 
| 
       210 
207 
     | 
    
         
             
                  # methods in ActiveModel::Type::Value for more details.
         
     | 
| 
       211 
     | 
    
         
            -
                  def attribute(name, cast_type = nil, **options 
     | 
| 
      
 208 
     | 
    
         
            +
                  def attribute(name, cast_type = nil, default: NO_DEFAULT_PROVIDED, **options)
         
     | 
| 
       212 
209 
     | 
    
         
             
                    name = name.to_s
         
     | 
| 
      
 210 
     | 
    
         
            +
                    name = attribute_aliases[name] || name
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
       213 
212 
     | 
    
         
             
                    reload_schema_from_cache
         
     | 
| 
       214 
213 
     | 
    
         | 
| 
      
 214 
     | 
    
         
            +
                    case cast_type
         
     | 
| 
      
 215 
     | 
    
         
            +
                    when Symbol
         
     | 
| 
      
 216 
     | 
    
         
            +
                      cast_type = Type.lookup(cast_type, **options, adapter: Type.adapter_name_from(self))
         
     | 
| 
      
 217 
     | 
    
         
            +
                    when nil
         
     | 
| 
      
 218 
     | 
    
         
            +
                      if (prev_cast_type, prev_default = attributes_to_define_after_schema_loads[name])
         
     | 
| 
      
 219 
     | 
    
         
            +
                        default = prev_default if default == NO_DEFAULT_PROVIDED
         
     | 
| 
      
 220 
     | 
    
         
            +
                      else
         
     | 
| 
      
 221 
     | 
    
         
            +
                        prev_cast_type = -> subtype { subtype }
         
     | 
| 
      
 222 
     | 
    
         
            +
                      end
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
                      cast_type = if block_given?
         
     | 
| 
      
 225 
     | 
    
         
            +
                        -> subtype { yield Proc === prev_cast_type ? prev_cast_type[subtype] : prev_cast_type }
         
     | 
| 
      
 226 
     | 
    
         
            +
                      else
         
     | 
| 
      
 227 
     | 
    
         
            +
                        prev_cast_type
         
     | 
| 
      
 228 
     | 
    
         
            +
                      end
         
     | 
| 
      
 229 
     | 
    
         
            +
                    end
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
       215 
231 
     | 
    
         
             
                    self.attributes_to_define_after_schema_loads =
         
     | 
| 
       216 
     | 
    
         
            -
                      attributes_to_define_after_schema_loads.merge(
         
     | 
| 
       217 
     | 
    
         
            -
                        name => [cast_type || block, options]
         
     | 
| 
       218 
     | 
    
         
            -
                      )
         
     | 
| 
      
 232 
     | 
    
         
            +
                      attributes_to_define_after_schema_loads.merge(name => [cast_type, default])
         
     | 
| 
       219 
233 
     | 
    
         
             
                  end
         
     | 
| 
       220 
234 
     | 
    
         | 
| 
       221 
235 
     | 
    
         
             
                  # This is the low level API which sits beneath +attribute+. It only
         
     | 
| 
         @@ -248,8 +262,9 @@ module ActiveRecord 
     | 
|
| 
       248 
262 
     | 
    
         | 
| 
       249 
263 
     | 
    
         
             
                  def load_schema! # :nodoc:
         
     | 
| 
       250 
264 
     | 
    
         
             
                    super
         
     | 
| 
       251 
     | 
    
         
            -
                    attributes_to_define_after_schema_loads.each do |name, ( 
     | 
| 
       252 
     | 
    
         
            -
                       
     | 
| 
      
 265 
     | 
    
         
            +
                    attributes_to_define_after_schema_loads.each do |name, (cast_type, default)|
         
     | 
| 
      
 266 
     | 
    
         
            +
                      cast_type = cast_type[type_for_attribute(name)] if Proc === cast_type
         
     | 
| 
      
 267 
     | 
    
         
            +
                      define_attribute(name, cast_type, default: default)
         
     | 
| 
       253 
268 
     | 
    
         
             
                    end
         
     | 
| 
       254 
269 
     | 
    
         
             
                  end
         
     | 
| 
       255 
270 
     | 
    
         | 
| 
         @@ -272,32 +287,6 @@ module ActiveRecord 
     | 
|
| 
       272 
287 
     | 
    
         
             
                      end
         
     | 
| 
       273 
288 
     | 
    
         
             
                      _default_attributes[name] = default_attribute
         
     | 
| 
       274 
289 
     | 
    
         
             
                    end
         
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
                    def decorate_attribute_type(attr_name, **default)
         
     | 
| 
       277 
     | 
    
         
            -
                      type, options = attributes_to_define_after_schema_loads[attr_name]
         
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
                      default.with_defaults!(default: options[:default]) if options&.key?(:default)
         
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
                      attribute(attr_name, **default) do |cast_type|
         
     | 
| 
       282 
     | 
    
         
            -
                        if type && !type.is_a?(Proc)
         
     | 
| 
       283 
     | 
    
         
            -
                          cast_type = _lookup_cast_type(attr_name, type, options)
         
     | 
| 
       284 
     | 
    
         
            -
                        end
         
     | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
                        yield cast_type
         
     | 
| 
       287 
     | 
    
         
            -
                      end
         
     | 
| 
       288 
     | 
    
         
            -
                    end
         
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
       290 
     | 
    
         
            -
                    def _lookup_cast_type(name, type, options)
         
     | 
| 
       291 
     | 
    
         
            -
                      case type
         
     | 
| 
       292 
     | 
    
         
            -
                      when Symbol
         
     | 
| 
       293 
     | 
    
         
            -
                        adapter_name = ActiveRecord::Type.adapter_name_from(self)
         
     | 
| 
       294 
     | 
    
         
            -
                        ActiveRecord::Type.lookup(type, **options.except(:default), adapter: adapter_name)
         
     | 
| 
       295 
     | 
    
         
            -
                      when Proc
         
     | 
| 
       296 
     | 
    
         
            -
                        type[type_for_attribute(name)]
         
     | 
| 
       297 
     | 
    
         
            -
                      else
         
     | 
| 
       298 
     | 
    
         
            -
                        type || type_for_attribute(name)
         
     | 
| 
       299 
     | 
    
         
            -
                      end
         
     | 
| 
       300 
     | 
    
         
            -
                    end
         
     | 
| 
       301 
290 
     | 
    
         
             
                end
         
     | 
| 
       302 
291 
     | 
    
         
             
              end
         
     | 
| 
       303 
292 
     | 
    
         
             
            end
         
     | 
| 
         @@ -26,7 +26,7 @@ module ActiveRecord 
     | 
|
| 
       26 
26 
     | 
    
         
             
              #
         
     | 
| 
       27 
27 
     | 
    
         
             
              # Child records are validated unless <tt>:validate</tt> is +false+.
         
     | 
| 
       28 
28 
     | 
    
         
             
              #
         
     | 
| 
       29 
     | 
    
         
            -
              # == Callbacks
         
     | 
| 
      
 29 
     | 
    
         
            +
              # == \Callbacks
         
     | 
| 
       30 
30 
     | 
    
         
             
              #
         
     | 
| 
       31 
31 
     | 
    
         
             
              # Association with autosave option defines several callbacks on your
         
     | 
| 
       32 
32 
     | 
    
         
             
              # model (around_save, before_save, after_create, after_update). Please note that
         
     | 
| 
         @@ -138,7 +138,7 @@ module ActiveRecord 
     | 
|
| 
       138 
138 
     | 
    
         
             
              module AutosaveAssociation
         
     | 
| 
       139 
139 
     | 
    
         
             
                extend ActiveSupport::Concern
         
     | 
| 
       140 
140 
     | 
    
         | 
| 
       141 
     | 
    
         
            -
                module AssociationBuilderExtension  
     | 
| 
      
 141 
     | 
    
         
            +
                module AssociationBuilderExtension # :nodoc:
         
     | 
| 
       142 
142 
     | 
    
         
             
                  def self.build(model, reflection)
         
     | 
| 
       143 
143 
     | 
    
         
             
                    model.send(:add_autosave_association_callbacks, reflection)
         
     | 
| 
       144 
144 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -150,25 +150,10 @@ module ActiveRecord 
     | 
|
| 
       150 
150 
     | 
    
         | 
| 
       151 
151 
     | 
    
         
             
                included do
         
     | 
| 
       152 
152 
     | 
    
         
             
                  Associations::Builder::Association.extensions << AssociationBuilderExtension
         
     | 
| 
       153 
     | 
    
         
            -
                  mattr_accessor :index_nested_attribute_errors, instance_writer: false, default: false
         
     | 
| 
       154 
153 
     | 
    
         
             
                end
         
     | 
| 
       155 
154 
     | 
    
         | 
| 
       156 
155 
     | 
    
         
             
                module ClassMethods # :nodoc:
         
     | 
| 
       157 
156 
     | 
    
         
             
                  private
         
     | 
| 
       158 
     | 
    
         
            -
                    if Module.method(:method_defined?).arity == 1 # MRI 2.5 and older
         
     | 
| 
       159 
     | 
    
         
            -
                      using Module.new {
         
     | 
| 
       160 
     | 
    
         
            -
                        refine Module do
         
     | 
| 
       161 
     | 
    
         
            -
                          def method_defined?(method, inherit = true)
         
     | 
| 
       162 
     | 
    
         
            -
                            if inherit
         
     | 
| 
       163 
     | 
    
         
            -
                              super(method)
         
     | 
| 
       164 
     | 
    
         
            -
                            else
         
     | 
| 
       165 
     | 
    
         
            -
                              instance_methods(false).include?(method.to_sym)
         
     | 
| 
       166 
     | 
    
         
            -
                            end
         
     | 
| 
       167 
     | 
    
         
            -
                          end
         
     | 
| 
       168 
     | 
    
         
            -
                        end
         
     | 
| 
       169 
     | 
    
         
            -
                      }
         
     | 
| 
       170 
     | 
    
         
            -
                    end
         
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
157 
     | 
    
         
             
                    def define_non_cyclic_method(name, &block)
         
     | 
| 
       173 
158 
     | 
    
         
             
                      return if method_defined?(name, false)
         
     | 
| 
       174 
159 
     | 
    
         | 
| 
         @@ -210,7 +195,7 @@ module ActiveRecord 
     | 
|
| 
       210 
195 
     | 
    
         
             
                        after_create save_method
         
     | 
| 
       211 
196 
     | 
    
         
             
                        after_update save_method
         
     | 
| 
       212 
197 
     | 
    
         
             
                      elsif reflection.has_one?
         
     | 
| 
       213 
     | 
    
         
            -
                         
     | 
| 
      
 198 
     | 
    
         
            +
                        define_non_cyclic_method(save_method) { save_has_one_association(reflection) }
         
     | 
| 
       214 
199 
     | 
    
         
             
                        # Configures two callbacks instead of a single after_save so that
         
     | 
| 
       215 
200 
     | 
    
         
             
                        # the model may rely on their execution order relative to its
         
     | 
| 
       216 
201 
     | 
    
         
             
                        # own callbacks.
         
     | 
| 
         @@ -288,6 +273,11 @@ module ActiveRecord 
     | 
|
| 
       288 
273 
     | 
    
         
             
                end
         
     | 
| 
       289 
274 
     | 
    
         | 
| 
       290 
275 
     | 
    
         
             
                private
         
     | 
| 
      
 276 
     | 
    
         
            +
                  def init_internals
         
     | 
| 
      
 277 
     | 
    
         
            +
                    super
         
     | 
| 
      
 278 
     | 
    
         
            +
                    @_already_called = nil
         
     | 
| 
      
 279 
     | 
    
         
            +
                  end
         
     | 
| 
      
 280 
     | 
    
         
            +
             
     | 
| 
       291 
281 
     | 
    
         
             
                  # Returns the record for an association collection that should be validated
         
     | 
| 
       292 
282 
     | 
    
         
             
                  # or saved. If +autosave+ is +false+ only new records will be returned,
         
     | 
| 
       293 
283 
     | 
    
         
             
                  # unless the parent is/was a new record itself.
         
     | 
| 
         @@ -349,7 +339,7 @@ module ActiveRecord 
     | 
|
| 
       349 
339 
     | 
    
         | 
| 
       350 
340 
     | 
    
         
             
                    unless valid = record.valid?(context)
         
     | 
| 
       351 
341 
     | 
    
         
             
                      if reflection.options[:autosave]
         
     | 
| 
       352 
     | 
    
         
            -
                        indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord 
     | 
| 
      
 342 
     | 
    
         
            +
                        indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord.index_nested_attribute_errors)
         
     | 
| 
       353 
343 
     | 
    
         | 
| 
       354 
344 
     | 
    
         
             
                        record.errors.group_by_attribute.each { |attribute, errors|
         
     | 
| 
       355 
345 
     | 
    
         
             
                          attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)
         
     | 
| 
         @@ -419,6 +409,8 @@ module ActiveRecord 
     | 
|
| 
       419 
409 
     | 
    
         
             
                          saved = true
         
     | 
| 
       420 
410 
     | 
    
         | 
| 
       421 
411 
     | 
    
         
             
                          if autosave != false && (new_record_before_save || record.new_record?)
         
     | 
| 
      
 412 
     | 
    
         
            +
                            association.set_inverse_instance(record)
         
     | 
| 
      
 413 
     | 
    
         
            +
             
     | 
| 
       422 
414 
     | 
    
         
             
                            if autosave
         
     | 
| 
       423 
415 
     | 
    
         
             
                              saved = association.insert_record(record, false)
         
     | 
| 
       424 
416 
     | 
    
         
             
                            elsif !reflection.nested?
         
     | 
| 
         @@ -457,14 +449,18 @@ module ActiveRecord 
     | 
|
| 
       457 
449 
     | 
    
         
             
                      if autosave && record.marked_for_destruction?
         
     | 
| 
       458 
450 
     | 
    
         
             
                        record.destroy
         
     | 
| 
       459 
451 
     | 
    
         
             
                      elsif autosave != false
         
     | 
| 
       460 
     | 
    
         
            -
                         
     | 
| 
      
 452 
     | 
    
         
            +
                        primary_key = Array(compute_primary_key(reflection, self)).map(&:to_s)
         
     | 
| 
      
 453 
     | 
    
         
            +
                        primary_key_value = primary_key.map { |key| _read_attribute(key) }
         
     | 
| 
       461 
454 
     | 
    
         | 
| 
       462 
     | 
    
         
            -
                        if (autosave && record.changed_for_autosave?) ||  
     | 
| 
      
 455 
     | 
    
         
            +
                        if (autosave && record.changed_for_autosave?) || _record_changed?(reflection, record, primary_key_value)
         
     | 
| 
       463 
456 
     | 
    
         
             
                          unless reflection.through_reflection
         
     | 
| 
       464 
     | 
    
         
            -
                             
     | 
| 
       465 
     | 
    
         
            -
                             
     | 
| 
       466 
     | 
    
         
            -
             
     | 
| 
      
 457 
     | 
    
         
            +
                            foreign_key = Array(reflection.foreign_key)
         
     | 
| 
      
 458 
     | 
    
         
            +
                            primary_key_foreign_key_pairs = primary_key.zip(foreign_key)
         
     | 
| 
      
 459 
     | 
    
         
            +
             
     | 
| 
      
 460 
     | 
    
         
            +
                            primary_key_foreign_key_pairs.each do |primary_key, foreign_key|
         
     | 
| 
      
 461 
     | 
    
         
            +
                              record[foreign_key] = _read_attribute(primary_key)
         
     | 
| 
       467 
462 
     | 
    
         
             
                            end
         
     | 
| 
      
 463 
     | 
    
         
            +
                            association.set_inverse_instance(record)
         
     | 
| 
       468 
464 
     | 
    
         
             
                          end
         
     | 
| 
       469 
465 
     | 
    
         | 
| 
       470 
466 
     | 
    
         
             
                          saved = record.save(validate: !autosave)
         
     | 
| 
         @@ -476,16 +472,28 @@ module ActiveRecord 
     | 
|
| 
       476 
472 
     | 
    
         
             
                  end
         
     | 
| 
       477 
473 
     | 
    
         | 
| 
       478 
474 
     | 
    
         
             
                  # If the record is new or it has changed, returns true.
         
     | 
| 
       479 
     | 
    
         
            -
                  def  
     | 
| 
      
 475 
     | 
    
         
            +
                  def _record_changed?(reflection, record, key)
         
     | 
| 
       480 
476 
     | 
    
         
             
                    record.new_record? ||
         
     | 
| 
       481 
     | 
    
         
            -
                      association_foreign_key_changed?(reflection, record, key) ||
         
     | 
| 
      
 477 
     | 
    
         
            +
                      (association_foreign_key_changed?(reflection, record, key) ||
         
     | 
| 
      
 478 
     | 
    
         
            +
                      inverse_polymorphic_association_changed?(reflection, record)) ||
         
     | 
| 
       482 
479 
     | 
    
         
             
                      record.will_save_change_to_attribute?(reflection.foreign_key)
         
     | 
| 
       483 
480 
     | 
    
         
             
                  end
         
     | 
| 
       484 
481 
     | 
    
         | 
| 
       485 
482 
     | 
    
         
             
                  def association_foreign_key_changed?(reflection, record, key)
         
     | 
| 
       486 
483 
     | 
    
         
             
                    return false if reflection.through_reflection?
         
     | 
| 
       487 
484 
     | 
    
         | 
| 
       488 
     | 
    
         
            -
                     
     | 
| 
      
 485 
     | 
    
         
            +
                    foreign_key = Array(reflection.foreign_key)
         
     | 
| 
      
 486 
     | 
    
         
            +
                    return false unless foreign_key.all? { |key| record._has_attribute?(key) }
         
     | 
| 
      
 487 
     | 
    
         
            +
             
     | 
| 
      
 488 
     | 
    
         
            +
                    foreign_key.map { |key| record._read_attribute(key) } != Array(key)
         
     | 
| 
      
 489 
     | 
    
         
            +
                  end
         
     | 
| 
      
 490 
     | 
    
         
            +
             
     | 
| 
      
 491 
     | 
    
         
            +
                  def inverse_polymorphic_association_changed?(reflection, record)
         
     | 
| 
      
 492 
     | 
    
         
            +
                    return false unless reflection.inverse_of&.polymorphic?
         
     | 
| 
      
 493 
     | 
    
         
            +
             
     | 
| 
      
 494 
     | 
    
         
            +
                    class_name = record._read_attribute(reflection.inverse_of.foreign_type)
         
     | 
| 
      
 495 
     | 
    
         
            +
             
     | 
| 
      
 496 
     | 
    
         
            +
                    reflection.active_record != record.class.polymorphic_class_for(class_name)
         
     | 
| 
       489 
497 
     | 
    
         
             
                  end
         
     | 
| 
       490 
498 
     | 
    
         | 
| 
       491 
499 
     | 
    
         
             
                  # Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
         
     | 
| 
         @@ -500,14 +508,21 @@ module ActiveRecord 
     | 
|
| 
       500 
508 
     | 
    
         
             
                      autosave = reflection.options[:autosave]
         
     | 
| 
       501 
509 
     | 
    
         | 
| 
       502 
510 
     | 
    
         
             
                      if autosave && record.marked_for_destruction?
         
     | 
| 
       503 
     | 
    
         
            -
                         
     | 
| 
      
 511 
     | 
    
         
            +
                        foreign_key = Array(reflection.foreign_key)
         
     | 
| 
      
 512 
     | 
    
         
            +
                        foreign_key.each { |key| self[key] = nil }
         
     | 
| 
       504 
513 
     | 
    
         
             
                        record.destroy
         
     | 
| 
       505 
514 
     | 
    
         
             
                      elsif autosave != false
         
     | 
| 
       506 
515 
     | 
    
         
             
                        saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
         
     | 
| 
       507 
516 
     | 
    
         | 
| 
       508 
517 
     | 
    
         
             
                        if association.updated?
         
     | 
| 
       509 
     | 
    
         
            -
                           
     | 
| 
       510 
     | 
    
         
            -
                           
     | 
| 
      
 518 
     | 
    
         
            +
                          primary_key = Array(compute_primary_key(reflection, record)).map(&:to_s)
         
     | 
| 
      
 519 
     | 
    
         
            +
                          foreign_key = Array(reflection.foreign_key)
         
     | 
| 
      
 520 
     | 
    
         
            +
             
     | 
| 
      
 521 
     | 
    
         
            +
                          primary_key_foreign_key_pairs = primary_key.zip(foreign_key)
         
     | 
| 
      
 522 
     | 
    
         
            +
                          primary_key_foreign_key_pairs.each do |primary_key, foreign_key|
         
     | 
| 
      
 523 
     | 
    
         
            +
                            association_id = record._read_attribute(primary_key)
         
     | 
| 
      
 524 
     | 
    
         
            +
                            self[foreign_key] = association_id unless self[foreign_key] == association_id
         
     | 
| 
      
 525 
     | 
    
         
            +
                          end
         
     | 
| 
       511 
526 
     | 
    
         
             
                          association.loaded!
         
     | 
| 
       512 
527 
     | 
    
         
             
                        end
         
     | 
| 
       513 
528 
     | 
    
         | 
| 
         @@ -516,6 +531,22 @@ module ActiveRecord 
     | 
|
| 
       516 
531 
     | 
    
         
             
                    end
         
     | 
| 
       517 
532 
     | 
    
         
             
                  end
         
     | 
| 
       518 
533 
     | 
    
         | 
| 
      
 534 
     | 
    
         
            +
                  def compute_primary_key(reflection, record)
         
     | 
| 
      
 535 
     | 
    
         
            +
                    if primary_key_options = reflection.options[:primary_key]
         
     | 
| 
      
 536 
     | 
    
         
            +
                      primary_key_options
         
     | 
| 
      
 537 
     | 
    
         
            +
                    elsif reflection.options[:query_constraints] && (query_constraints = record.class.query_constraints_list)
         
     | 
| 
      
 538 
     | 
    
         
            +
                      query_constraints
         
     | 
| 
      
 539 
     | 
    
         
            +
                    elsif record.class.has_query_constraints? && !reflection.options[:foreign_key]
         
     | 
| 
      
 540 
     | 
    
         
            +
                      record.class.query_constraints_list
         
     | 
| 
      
 541 
     | 
    
         
            +
                    elsif record.class.composite_primary_key?
         
     | 
| 
      
 542 
     | 
    
         
            +
                      # If record has composite primary key of shape [:<tenant_key>, :id], infer primary_key as :id
         
     | 
| 
      
 543 
     | 
    
         
            +
                      primary_key = record.class.primary_key
         
     | 
| 
      
 544 
     | 
    
         
            +
                      primary_key.include?("id") ? "id" : primary_key
         
     | 
| 
      
 545 
     | 
    
         
            +
                    else
         
     | 
| 
      
 546 
     | 
    
         
            +
                      record.class.primary_key
         
     | 
| 
      
 547 
     | 
    
         
            +
                    end
         
     | 
| 
      
 548 
     | 
    
         
            +
                  end
         
     | 
| 
      
 549 
     | 
    
         
            +
             
     | 
| 
       519 
550 
     | 
    
         
             
                  def custom_validation_context?
         
     | 
| 
       520 
551 
     | 
    
         
             
                    validation_context && [:create, :update].exclude?(validation_context)
         
     | 
| 
       521 
552 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/active_record/base.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ require "active_record/attributes" 
     | 
|
| 
       12 
12 
     | 
    
         
             
            require "active_record/type_caster"
         
     | 
| 
       13 
13 
     | 
    
         
             
            require "active_record/database_configurations"
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            module ActiveRecord  
     | 
| 
      
 15 
     | 
    
         
            +
            module ActiveRecord # :nodoc:
         
     | 
| 
       16 
16 
     | 
    
         
             
              # = Active Record
         
     | 
| 
       17 
17 
     | 
    
         
             
              #
         
     | 
| 
       18 
18 
     | 
    
         
             
              # Active Record objects don't specify their attributes directly, but rather infer them from
         
     | 
| 
         @@ -137,6 +137,23 @@ module ActiveRecord #:nodoc: 
     | 
|
| 
       137 
137 
     | 
    
         
             
              #   anonymous = User.new(name: "")
         
     | 
| 
       138 
138 
     | 
    
         
             
              #   anonymous.name? # => false
         
     | 
| 
       139 
139 
     | 
    
         
             
              #
         
     | 
| 
      
 140 
     | 
    
         
            +
              # Query methods will also respect any overrides of default accessors:
         
     | 
| 
      
 141 
     | 
    
         
            +
              #
         
     | 
| 
      
 142 
     | 
    
         
            +
              #   class User
         
     | 
| 
      
 143 
     | 
    
         
            +
              #     # Has admin boolean column
         
     | 
| 
      
 144 
     | 
    
         
            +
              #     def admin
         
     | 
| 
      
 145 
     | 
    
         
            +
              #       false
         
     | 
| 
      
 146 
     | 
    
         
            +
              #     end
         
     | 
| 
      
 147 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 148 
     | 
    
         
            +
              #
         
     | 
| 
      
 149 
     | 
    
         
            +
              #   user.update(admin: true)
         
     | 
| 
      
 150 
     | 
    
         
            +
              #
         
     | 
| 
      
 151 
     | 
    
         
            +
              #   user.read_attribute(:admin)  # => true, gets the column value
         
     | 
| 
      
 152 
     | 
    
         
            +
              #   user[:admin] # => true, also gets the column value
         
     | 
| 
      
 153 
     | 
    
         
            +
              #
         
     | 
| 
      
 154 
     | 
    
         
            +
              #   user.admin   # => false, due to the getter override
         
     | 
| 
      
 155 
     | 
    
         
            +
              #   user.admin?  # => false, due to the getter override
         
     | 
| 
      
 156 
     | 
    
         
            +
              #
         
     | 
| 
       140 
157 
     | 
    
         
             
              # == Accessing attributes before they have been typecasted
         
     | 
| 
       141 
158 
     | 
    
         
             
              #
         
     | 
| 
       142 
159 
     | 
    
         
             
              # Sometimes you want to be able to read the raw attribute data without having the column-determined
         
     | 
| 
         @@ -294,11 +311,12 @@ module ActiveRecord #:nodoc: 
     | 
|
| 
       294 
311 
     | 
    
         
             
                include Attributes
         
     | 
| 
       295 
312 
     | 
    
         
             
                include Locking::Optimistic
         
     | 
| 
       296 
313 
     | 
    
         
             
                include Locking::Pessimistic
         
     | 
| 
      
 314 
     | 
    
         
            +
                include Encryption::EncryptableRecord
         
     | 
| 
       297 
315 
     | 
    
         
             
                include AttributeMethods
         
     | 
| 
       298 
316 
     | 
    
         
             
                include Callbacks
         
     | 
| 
       299 
317 
     | 
    
         
             
                include Timestamp
         
     | 
| 
       300 
318 
     | 
    
         
             
                include Associations
         
     | 
| 
       301 
     | 
    
         
            -
                include  
     | 
| 
      
 319 
     | 
    
         
            +
                include SecurePassword
         
     | 
| 
       302 
320 
     | 
    
         
             
                include AutosaveAssociation
         
     | 
| 
       303 
321 
     | 
    
         
             
                include NestedAttributes
         
     | 
| 
       304 
322 
     | 
    
         
             
                include Transactions
         
     | 
| 
         @@ -308,8 +326,13 @@ module ActiveRecord #:nodoc: 
     | 
|
| 
       308 
326 
     | 
    
         
             
                include Serialization
         
     | 
| 
       309 
327 
     | 
    
         
             
                include Store
         
     | 
| 
       310 
328 
     | 
    
         
             
                include SecureToken
         
     | 
| 
      
 329 
     | 
    
         
            +
                include TokenFor
         
     | 
| 
       311 
330 
     | 
    
         
             
                include SignedId
         
     | 
| 
       312 
331 
     | 
    
         
             
                include Suppressor
         
     | 
| 
      
 332 
     | 
    
         
            +
                include Normalization
         
     | 
| 
      
 333 
     | 
    
         
            +
                include Marshalling::Methods
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
                self.param_delimiter = "_"
         
     | 
| 
       313 
336 
     | 
    
         
             
              end
         
     | 
| 
       314 
337 
     | 
    
         | 
| 
       315 
338 
     | 
    
         
             
              ActiveSupport.run_load_hooks(:active_record, Base)
         
     | 
| 
         @@ -84,7 +84,7 @@ module ActiveRecord 
     | 
|
| 
       84 
84 
     | 
    
         
             
              # == Types of callbacks
         
     | 
| 
       85 
85 
     | 
    
         
             
              #
         
     | 
| 
       86 
86 
     | 
    
         
             
              # There are three types of callbacks accepted by the callback macros: method references (symbol), callback objects,
         
     | 
| 
       87 
     | 
    
         
            -
              # inline methods (using a proc). Method references and callback objects are the recommended approaches,
         
     | 
| 
      
 87 
     | 
    
         
            +
              # inline methods (using a proc). \Method references and callback objects are the recommended approaches,
         
     | 
| 
       88 
88 
     | 
    
         
             
              # inline methods using a proc are sometimes appropriate (such as for creating mix-ins).
         
     | 
| 
       89 
89 
     | 
    
         
             
              #
         
     | 
| 
       90 
90 
     | 
    
         
             
              # The method reference callbacks work by specifying a protected or private method available in the object, like this:
         
     | 
| 
         @@ -173,7 +173,7 @@ module ActiveRecord 
     | 
|
| 
       173 
173 
     | 
    
         
             
              #
         
     | 
| 
       174 
174 
     | 
    
         
             
              # If a <tt>before_*</tt> callback throws +:abort+, all the later callbacks and
         
     | 
| 
       175 
175 
     | 
    
         
             
              # the associated action are cancelled.
         
     | 
| 
       176 
     | 
    
         
            -
              # Callbacks are generally run in the order they are defined, with the exception of callbacks defined as
         
     | 
| 
      
 176 
     | 
    
         
            +
              # \Callbacks are generally run in the order they are defined, with the exception of callbacks defined as
         
     | 
| 
       177 
177 
     | 
    
         
             
              # methods on the model, which are called last.
         
     | 
| 
       178 
178 
     | 
    
         
             
              #
         
     | 
| 
       179 
179 
     | 
    
         
             
              # == Ordering callbacks
         
     | 
| 
         @@ -224,42 +224,26 @@ module ActiveRecord 
     | 
|
| 
       224 
224 
     | 
    
         
             
              #     after_save :do_something_else
         
     | 
| 
       225 
225 
     | 
    
         
             
              #
         
     | 
| 
       226 
226 
     | 
    
         
             
              #     private
         
     | 
| 
      
 227 
     | 
    
         
            +
              #       def log_children
         
     | 
| 
      
 228 
     | 
    
         
            +
              #         # Child processing
         
     | 
| 
      
 229 
     | 
    
         
            +
              #       end
         
     | 
| 
       227 
230 
     | 
    
         
             
              #
         
     | 
| 
       228 
     | 
    
         
            -
              # 
     | 
| 
       229 
     | 
    
         
            -
              # 
     | 
| 
       230 
     | 
    
         
            -
              # 
     | 
| 
       231 
     | 
    
         
            -
              #
         
     | 
| 
       232 
     | 
    
         
            -
              #     def do_something_else
         
     | 
| 
       233 
     | 
    
         
            -
              #       # Something else
         
     | 
| 
       234 
     | 
    
         
            -
              #     end
         
     | 
| 
      
 231 
     | 
    
         
            +
              #       def do_something_else
         
     | 
| 
      
 232 
     | 
    
         
            +
              #         # Something else
         
     | 
| 
      
 233 
     | 
    
         
            +
              #       end
         
     | 
| 
       235 
234 
     | 
    
         
             
              #   end
         
     | 
| 
       236 
235 
     | 
    
         
             
              #
         
     | 
| 
       237 
236 
     | 
    
         
             
              # In this case the +log_children+ is executed before +do_something_else+.
         
     | 
| 
       238 
     | 
    
         
            -
              #  
     | 
| 
      
 237 
     | 
    
         
            +
              # This applies to all non-transactional callbacks, and to +before_commit+.
         
     | 
| 
       239 
238 
     | 
    
         
             
              #
         
     | 
| 
       240 
     | 
    
         
            -
              #  
     | 
| 
       241 
     | 
    
         
            -
              #  
     | 
| 
      
 239 
     | 
    
         
            +
              # For transactional +after_+ callbacks (+after_commit+, +after_rollback+, etc), the order
         
     | 
| 
      
 240 
     | 
    
         
            +
              # can be set via configuration.
         
     | 
| 
       242 
241 
     | 
    
         
             
              #
         
     | 
| 
       243 
     | 
    
         
            -
              #  
     | 
| 
       244 
     | 
    
         
            -
              #
         
     | 
| 
       245 
     | 
    
         
            -
              #   class Topic < ActiveRecord::Base
         
     | 
| 
       246 
     | 
    
         
            -
              #     has_many :children
         
     | 
| 
       247 
     | 
    
         
            -
              #
         
     | 
| 
       248 
     | 
    
         
            -
              #     after_commit :log_children
         
     | 
| 
       249 
     | 
    
         
            -
              #     after_commit :do_something_else
         
     | 
| 
       250 
     | 
    
         
            -
              #
         
     | 
| 
       251 
     | 
    
         
            -
              #     private
         
     | 
| 
       252 
     | 
    
         
            -
              #
         
     | 
| 
       253 
     | 
    
         
            -
              #     def log_children
         
     | 
| 
       254 
     | 
    
         
            -
              #       # Child processing
         
     | 
| 
       255 
     | 
    
         
            -
              #     end
         
     | 
| 
       256 
     | 
    
         
            -
              #
         
     | 
| 
       257 
     | 
    
         
            -
              #     def do_something_else
         
     | 
| 
       258 
     | 
    
         
            -
              #       # Something else
         
     | 
| 
       259 
     | 
    
         
            -
              #     end
         
     | 
| 
       260 
     | 
    
         
            -
              #   end
         
     | 
| 
      
 242 
     | 
    
         
            +
              #   config.active_record.run_after_transaction_callbacks_in_order_defined = false
         
     | 
| 
       261 
243 
     | 
    
         
             
              #
         
     | 
| 
       262 
     | 
    
         
            -
              #  
     | 
| 
      
 244 
     | 
    
         
            +
              # When set to +true+ (the default from \Rails 7.1), callbacks are executed in the order they
         
     | 
| 
      
 245 
     | 
    
         
            +
              # are defined, just like the example above. When set to +false+, the order is reversed, so
         
     | 
| 
      
 246 
     | 
    
         
            +
              # +do_something_else+ is executed before +log_children+.
         
     | 
| 
       263 
247 
     | 
    
         
             
              #
         
     | 
| 
       264 
248 
     | 
    
         
             
              # == \Transactions
         
     | 
| 
       265 
249 
     | 
    
         
             
              #
         
     | 
| 
         @@ -432,7 +416,7 @@ module ActiveRecord 
     | 
|
| 
       432 
416 
     | 
    
         
             
                  define_model_callbacks :save, :create, :update, :destroy
         
     | 
| 
       433 
417 
     | 
    
         
             
                end
         
     | 
| 
       434 
418 
     | 
    
         | 
| 
       435 
     | 
    
         
            -
                def destroy  
     | 
| 
      
 419 
     | 
    
         
            +
                def destroy # :nodoc:
         
     | 
| 
       436 
420 
     | 
    
         
             
                  @_destroy_callback_already_called ||= false
         
     | 
| 
       437 
421 
     | 
    
         
             
                  return if @_destroy_callback_already_called
         
     | 
| 
       438 
422 
     | 
    
         
             
                  @_destroy_callback_already_called = true
         
     | 
| 
         @@ -444,7 +428,7 @@ module ActiveRecord 
     | 
|
| 
       444 
428 
     | 
    
         
             
                  @_destroy_callback_already_called = false
         
     | 
| 
       445 
429 
     | 
    
         
             
                end
         
     | 
| 
       446 
430 
     | 
    
         | 
| 
       447 
     | 
    
         
            -
                def touch(*, **)  
     | 
| 
      
 431 
     | 
    
         
            +
                def touch(*, **) # :nodoc:
         
     | 
| 
       448 
432 
     | 
    
         
             
                  _run_touch_callbacks { super }
         
     | 
| 
       449 
433 
     | 
    
         
             
                end
         
     | 
| 
       450 
434 
     | 
    
         | 
| 
         @@ -462,7 +446,7 @@ module ActiveRecord 
     | 
|
| 
       462 
446 
     | 
    
         
             
                end
         
     | 
| 
       463 
447 
     | 
    
         | 
| 
       464 
448 
     | 
    
         
             
                def _update_record
         
     | 
| 
       465 
     | 
    
         
            -
                  _run_update_callbacks { super }
         
     | 
| 
      
 449 
     | 
    
         
            +
                  _run_update_callbacks { record_update_timestamps { super } }
         
     | 
| 
       466 
450 
     | 
    
         
             
                end
         
     | 
| 
       467 
451 
     | 
    
         
             
              end
         
     | 
| 
       468 
452 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module ActiveRecord
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Coders # :nodoc:
         
     | 
| 
      
 5 
     | 
    
         
            +
                class ColumnSerializer # :nodoc:
         
     | 
| 
      
 6 
     | 
    
         
            +
                  attr_reader :object_class
         
     | 
| 
      
 7 
     | 
    
         
            +
                  attr_reader :coder
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  def initialize(attr_name, coder, object_class = Object)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @attr_name = attr_name
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @object_class = object_class
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @coder = coder
         
     | 
| 
      
 13 
     | 
    
         
            +
                    check_arity_of_constructor
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def init_with(coder) # :nodoc:
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @attr_name = coder["attr_name"]
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @object_class = coder["object_class"]
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @coder = coder["coder"]
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def dump(object)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    return if object.nil?
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    assert_valid_value(object, action: "dump")
         
     | 
| 
      
 26 
     | 
    
         
            +
                    coder.dump(object)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  def load(payload)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    if payload.nil?
         
     | 
| 
      
 31 
     | 
    
         
            +
                      if @object_class != ::Object
         
     | 
| 
      
 32 
     | 
    
         
            +
                        return @object_class.new
         
     | 
| 
      
 33 
     | 
    
         
            +
                      end
         
     | 
| 
      
 34 
     | 
    
         
            +
                      return nil
         
     | 
| 
      
 35 
     | 
    
         
            +
                    end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    object = coder.load(payload)
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    assert_valid_value(object, action: "load")
         
     | 
| 
      
 40 
     | 
    
         
            +
                    object ||= object_class.new if object_class != Object
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                    object
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  # Public because it's called by Type::Serialized
         
     | 
| 
      
 46 
     | 
    
         
            +
                  def assert_valid_value(object, action:)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    unless object.nil? || object_class === object
         
     | 
| 
      
 48 
     | 
    
         
            +
                      raise SerializationTypeMismatch,
         
     | 
| 
      
 49 
     | 
    
         
            +
                        "can't #{action} `#{@attr_name}`: was supposed to be a #{object_class}, but was a #{object.class}. -- #{object.inspect}"
         
     | 
| 
      
 50 
     | 
    
         
            +
                    end
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  private
         
     | 
| 
      
 54 
     | 
    
         
            +
                    def check_arity_of_constructor
         
     | 
| 
      
 55 
     | 
    
         
            +
                      load(nil)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    rescue ArgumentError
         
     | 
| 
      
 57 
     | 
    
         
            +
                      raise ArgumentError, "Cannot serialize #{object_class}. Classes passed to `serialize` must have a 0 argument constructor."
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -4,37 +4,83 @@ require "yaml" 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            module ActiveRecord
         
     | 
| 
       6 
6 
     | 
    
         
             
              module Coders # :nodoc:
         
     | 
| 
       7 
     | 
    
         
            -
                class YAMLColumn # :nodoc:
         
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
                    check_arity_of_constructor
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
      
 7 
     | 
    
         
            +
                class YAMLColumn < ColumnSerializer # :nodoc:
         
     | 
| 
      
 8 
     | 
    
         
            +
                  class SafeCoder
         
     | 
| 
      
 9 
     | 
    
         
            +
                    def initialize(permitted_classes: [], unsafe_load: nil)
         
     | 
| 
      
 10 
     | 
    
         
            +
                      @permitted_classes = permitted_classes
         
     | 
| 
      
 11 
     | 
    
         
            +
                      @unsafe_load = unsafe_load
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                    if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("5.1")
         
     | 
| 
      
 15 
     | 
    
         
            +
                      def dump(object)
         
     | 
| 
      
 16 
     | 
    
         
            +
                        if @unsafe_load.nil? ? ActiveRecord.use_yaml_unsafe_load : @unsafe_load
         
     | 
| 
      
 17 
     | 
    
         
            +
                          ::YAML.dump(object)
         
     | 
| 
      
 18 
     | 
    
         
            +
                        else
         
     | 
| 
      
 19 
     | 
    
         
            +
                          ::YAML.safe_dump(
         
     | 
| 
      
 20 
     | 
    
         
            +
                            object,
         
     | 
| 
      
 21 
     | 
    
         
            +
                            permitted_classes: @permitted_classes + ActiveRecord.yaml_column_permitted_classes,
         
     | 
| 
      
 22 
     | 
    
         
            +
                            aliases: true,
         
     | 
| 
      
 23 
     | 
    
         
            +
                          )
         
     | 
| 
      
 24 
     | 
    
         
            +
                        end
         
     | 
| 
      
 25 
     | 
    
         
            +
                      end
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      def dump(object)
         
     | 
| 
      
 28 
     | 
    
         
            +
                        YAML.dump(object)
         
     | 
| 
      
 29 
     | 
    
         
            +
                      end
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
       18 
31 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                     
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                    if YAML.respond_to?(:unsafe_load)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      def load(payload)
         
     | 
| 
      
 34 
     | 
    
         
            +
                        if @unsafe_load.nil? ? ActiveRecord.use_yaml_unsafe_load : @unsafe_load
         
     | 
| 
      
 35 
     | 
    
         
            +
                          YAML.unsafe_load(payload)
         
     | 
| 
      
 36 
     | 
    
         
            +
                        else
         
     | 
| 
      
 37 
     | 
    
         
            +
                          YAML.safe_load(
         
     | 
| 
      
 38 
     | 
    
         
            +
                            payload,
         
     | 
| 
      
 39 
     | 
    
         
            +
                            permitted_classes: @permitted_classes + ActiveRecord.yaml_column_permitted_classes,
         
     | 
| 
      
 40 
     | 
    
         
            +
                            aliases: true,
         
     | 
| 
      
 41 
     | 
    
         
            +
                          )
         
     | 
| 
      
 42 
     | 
    
         
            +
                        end
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    else
         
     | 
| 
      
 45 
     | 
    
         
            +
                      def load(payload)
         
     | 
| 
      
 46 
     | 
    
         
            +
                        if @unsafe_load.nil? ? ActiveRecord.use_yaml_unsafe_load : @unsafe_load
         
     | 
| 
      
 47 
     | 
    
         
            +
                          YAML.load(payload)
         
     | 
| 
      
 48 
     | 
    
         
            +
                        else
         
     | 
| 
      
 49 
     | 
    
         
            +
                          YAML.safe_load(
         
     | 
| 
      
 50 
     | 
    
         
            +
                            payload,
         
     | 
| 
      
 51 
     | 
    
         
            +
                            permitted_classes: @permitted_classes + ActiveRecord.yaml_column_permitted_classes,
         
     | 
| 
      
 52 
     | 
    
         
            +
                            aliases: true,
         
     | 
| 
      
 53 
     | 
    
         
            +
                          )
         
     | 
| 
      
 54 
     | 
    
         
            +
                        end
         
     | 
| 
      
 55 
     | 
    
         
            +
                      end
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
       21 
57 
     | 
    
         
             
                  end
         
     | 
| 
       22 
58 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  def  
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                     
     | 
| 
       29 
     | 
    
         
            -
                     
     | 
| 
      
 59 
     | 
    
         
            +
                  def initialize(attr_name, object_class = Object, permitted_classes: [], unsafe_load: nil)
         
     | 
| 
      
 60 
     | 
    
         
            +
                    super(
         
     | 
| 
      
 61 
     | 
    
         
            +
                      attr_name,
         
     | 
| 
      
 62 
     | 
    
         
            +
                      SafeCoder.new(permitted_classes: permitted_classes || [], unsafe_load: unsafe_load),
         
     | 
| 
      
 63 
     | 
    
         
            +
                      object_class,
         
     | 
| 
      
 64 
     | 
    
         
            +
                    )
         
     | 
| 
      
 65 
     | 
    
         
            +
                    check_arity_of_constructor
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
       30 
67 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
                  def init_with(coder) # :nodoc:
         
     | 
| 
      
 69 
     | 
    
         
            +
                    unless coder["coder"]
         
     | 
| 
      
 70 
     | 
    
         
            +
                      permitted_classes = coder["permitted_classes"] || []
         
     | 
| 
      
 71 
     | 
    
         
            +
                      unsafe_load = coder["unsafe_load"] || false
         
     | 
| 
      
 72 
     | 
    
         
            +
                      coder["coder"] = SafeCoder.new(permitted_classes: permitted_classes, unsafe_load: unsafe_load)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                    super(coder)
         
     | 
| 
       32 
75 
     | 
    
         
             
                  end
         
     | 
| 
       33 
76 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                  def  
     | 
| 
       35 
     | 
    
         
            -
                     
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                  def coder
         
     | 
| 
      
 78 
     | 
    
         
            +
                    # This is to retain forward compatibility when loading records serialized with Marshal
         
     | 
| 
      
 79 
     | 
    
         
            +
                    # from a previous version of Rails.
         
     | 
| 
      
 80 
     | 
    
         
            +
                    @coder ||= begin
         
     | 
| 
      
 81 
     | 
    
         
            +
                      permitted_classes = defined?(@permitted_classes) ? @permitted_classes : []
         
     | 
| 
      
 82 
     | 
    
         
            +
                      unsafe_load = defined?(@unsafe_load) && @unsafe_load.nil?
         
     | 
| 
      
 83 
     | 
    
         
            +
                      SafeCoder.new(permitted_classes: permitted_classes, unsafe_load: unsafe_load)
         
     | 
| 
       38 
84 
     | 
    
         
             
                    end
         
     | 
| 
       39 
85 
     | 
    
         
             
                  end
         
     | 
| 
       40 
86 
     | 
    
         | 
| 
         @@ -44,16 +90,6 @@ module ActiveRecord 
     | 
|
| 
       44 
90 
     | 
    
         
             
                    rescue ArgumentError
         
     | 
| 
       45 
91 
     | 
    
         
             
                      raise ArgumentError, "Cannot serialize #{object_class}. Classes passed to `serialize` must have a 0 argument constructor."
         
     | 
| 
       46 
92 
     | 
    
         
             
                    end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                    if YAML.respond_to?(:unsafe_load)
         
     | 
| 
       49 
     | 
    
         
            -
                      def yaml_load(payload)
         
     | 
| 
       50 
     | 
    
         
            -
                        YAML.unsafe_load(payload)
         
     | 
| 
       51 
     | 
    
         
            -
                      end
         
     | 
| 
       52 
     | 
    
         
            -
                    else
         
     | 
| 
       53 
     | 
    
         
            -
                      def yaml_load(payload)
         
     | 
| 
       54 
     | 
    
         
            -
                        YAML.load(payload)
         
     | 
| 
       55 
     | 
    
         
            -
                      end
         
     | 
| 
       56 
     | 
    
         
            -
                    end
         
     | 
| 
       57 
93 
     | 
    
         
             
                end
         
     | 
| 
       58 
94 
     | 
    
         
             
              end
         
     | 
| 
       59 
95 
     | 
    
         
             
            end
         
     |