activerecord 6.1.7 → 7.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +616 -1290
- data/MIT-LICENSE +1 -1
- data/README.rdoc +31 -31
- data/examples/performance.rb +2 -2
- data/lib/active_record/aggregations.rb +17 -14
- data/lib/active_record/association_relation.rb +2 -12
- data/lib/active_record/associations/alias_tracker.rb +25 -19
- data/lib/active_record/associations/association.rb +60 -21
- data/lib/active_record/associations/association_scope.rb +17 -12
- data/lib/active_record/associations/belongs_to_association.rb +37 -11
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -4
- data/lib/active_record/associations/builder/association.rb +11 -5
- data/lib/active_record/associations/builder/belongs_to.rb +41 -14
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -7
- data/lib/active_record/associations/builder/has_many.rb +4 -4
- data/lib/active_record/associations/builder/has_one.rb +4 -4
- data/lib/active_record/associations/builder/singular_association.rb +6 -2
- data/lib/active_record/associations/collection_association.rb +46 -36
- data/lib/active_record/associations/collection_proxy.rb +44 -16
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/foreign_association.rb +10 -3
- data/lib/active_record/associations/has_many_association.rb +29 -19
- data/lib/active_record/associations/has_many_through_association.rb +19 -8
- 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/join_association.rb +30 -27
- data/lib/active_record/associations/join_dependency.rb +28 -20
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +212 -53
- data/lib/active_record/associations/preloader/batch.rb +48 -0
- data/lib/active_record/associations/preloader/branch.rb +153 -0
- data/lib/active_record/associations/preloader/through_association.rb +50 -16
- data/lib/active_record/associations/preloader.rb +50 -121
- data/lib/active_record/associations/singular_association.rb +15 -3
- data/lib/active_record/associations/through_association.rb +25 -14
- data/lib/active_record/associations.rb +429 -522
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +1 -5
- data/lib/active_record/attribute_methods/before_type_cast.rb +24 -2
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/dirty.rb +73 -22
- data/lib/active_record/attribute_methods/primary_key.rb +47 -27
- data/lib/active_record/attribute_methods/query.rb +31 -19
- data/lib/active_record/attribute_methods/read.rb +14 -11
- data/lib/active_record/attribute_methods/serialization.rb +174 -37
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +15 -9
- data/lib/active_record/attribute_methods/write.rb +12 -15
- data/lib/active_record/attribute_methods.rb +164 -52
- data/lib/active_record/attributes.rb +57 -54
- data/lib/active_record/autosave_association.rb +74 -57
- data/lib/active_record/base.rb +27 -5
- data/lib/active_record/callbacks.rb +19 -35
- 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 -46
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +284 -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 +79 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +325 -604
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +199 -60
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +230 -64
- data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -131
- 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 +378 -143
- data/lib/active_record/connection_adapters/abstract/transaction.rb +361 -76
- data/lib/active_record/connection_adapters/abstract_adapter.rb +624 -163
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +348 -165
- 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 +29 -130
- data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -55
- 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 +45 -14
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +152 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +107 -68
- data/lib/active_record/connection_adapters/pool_config.rb +26 -16
- 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 +114 -54
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -0
- 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/interval.rb +1 -1
- 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/uuid.rb +14 -4
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +137 -104
- 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 +173 -3
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +403 -77
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +520 -253
- data/lib/active_record/connection_adapters/schema_cache.rb +326 -102
- data/lib/active_record/connection_adapters/sqlite3/column.rb +62 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +78 -55
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +68 -54
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +20 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +66 -22
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +372 -130
- 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 +229 -0
- data/lib/active_record/connection_adapters.rb +130 -6
- data/lib/active_record/connection_handling.rb +132 -146
- data/lib/active_record/core.rb +310 -253
- data/lib/active_record/counter_cache.rb +68 -34
- data/lib/active_record/database_configurations/connection_url_resolver.rb +10 -4
- data/lib/active_record/database_configurations/database_config.rb +34 -10
- data/lib/active_record/database_configurations/hash_config.rb +107 -31
- data/lib/active_record/database_configurations/url_config.rb +38 -13
- data/lib/active_record/database_configurations.rb +96 -60
- data/lib/active_record/delegated_type.rb +90 -20
- data/lib/active_record/deprecator.rb +7 -0
- data/lib/active_record/destroy_association_async_job.rb +4 -2
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +3 -3
- 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 +230 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +175 -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 +170 -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_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +96 -0
- data/lib/active_record/encryption/null_encryptor.rb +25 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +28 -0
- data/lib/active_record/encryption/scheme.rb +100 -0
- data/lib/active_record/encryption.rb +58 -0
- data/lib/active_record/enum.rb +170 -62
- data/lib/active_record/errors.rb +210 -27
- data/lib/active_record/explain.rb +21 -12
- 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 +179 -112
- data/lib/active_record/future_result.rb +178 -0
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +85 -31
- data/lib/active_record/insert_all.rb +148 -32
- data/lib/active_record/integration.rb +14 -10
- data/lib/active_record/internal_metadata.rb +123 -23
- data/lib/active_record/legacy_yaml_adapter.rb +2 -39
- data/lib/active_record/locking/optimistic.rb +43 -27
- data/lib/active_record/locking/pessimistic.rb +15 -6
- data/lib/active_record/log_subscriber.rb +41 -29
- data/lib/active_record/marshalling.rb +59 -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 +113 -16
- data/lib/active_record/migration/compatibility.rb +235 -46
- data/lib/active_record/migration/default_strategy.rb +22 -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 +374 -177
- data/lib/active_record/model_schema.rb +145 -158
- data/lib/active_record/nested_attributes.rb +61 -23
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/normalization.rb +163 -0
- data/lib/active_record/persistence.rb +282 -283
- data/lib/active_record/promise.rb +84 -0
- data/lib/active_record/query_cache.rb +18 -25
- data/lib/active_record/query_logs.rb +189 -0
- data/lib/active_record/query_logs_formatter.rb +41 -0
- data/lib/active_record/querying.rb +44 -9
- data/lib/active_record/railtie.rb +229 -71
- data/lib/active_record/railties/controller_runtime.rb +25 -11
- data/lib/active_record/railties/databases.rake +189 -256
- 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 +332 -103
- data/lib/active_record/relation/batches/batch_enumerator.rb +38 -9
- data/lib/active_record/relation/batches.rb +200 -65
- data/lib/active_record/relation/calculations.rb +301 -112
- data/lib/active_record/relation/delegation.rb +33 -22
- data/lib/active_record/relation/finder_methods.rb +123 -52
- data/lib/active_record/relation/merger.rb +26 -19
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +38 -4
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -7
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
- data/lib/active_record/relation/predicate_builder.rb +29 -22
- data/lib/active_record/relation/query_attribute.rb +30 -12
- data/lib/active_record/relation/query_methods.rb +870 -163
- data/lib/active_record/relation/record_fetch_warning.rb +10 -9
- data/lib/active_record/relation/spawn_methods.rb +7 -6
- data/lib/active_record/relation/where_clause.rb +15 -36
- data/lib/active_record/relation.rb +736 -145
- data/lib/active_record/result.rb +67 -54
- data/lib/active_record/runtime_registry.rb +71 -13
- data/lib/active_record/sanitization.rb +84 -34
- data/lib/active_record/schema.rb +39 -23
- data/lib/active_record/schema_dumper.rb +90 -31
- data/lib/active_record/schema_migration.rb +74 -23
- data/lib/active_record/scoping/default.rb +72 -15
- data/lib/active_record/scoping/named.rb +6 -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 +30 -9
- data/lib/active_record/statement_cache.rb +7 -7
- data/lib/active_record/store.rb +10 -10
- data/lib/active_record/suppressor.rb +13 -15
- data/lib/active_record/table_metadata.rb +7 -3
- data/lib/active_record/tasks/database_tasks.rb +288 -149
- 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 +16 -7
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +173 -155
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +32 -19
- data/lib/active_record/token_for.rb +123 -0
- data/lib/active_record/touch_later.rb +12 -7
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +118 -41
- data/lib/active_record/translation.rb +3 -5
- 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 -7
- 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/type_caster/connection.rb +4 -4
- data/lib/active_record/validations/absence.rb +1 -1
- data/lib/active_record/validations/associated.rb +13 -7
- 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 +65 -15
- data/lib/active_record/validations.rb +12 -5
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +444 -32
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/collectors/bind.rb +2 -0
- data/lib/arel/collectors/composite.rb +7 -0
- data/lib/arel/collectors/sql_string.rb +1 -1
- data/lib/arel/collectors/substitute_binds.rb +1 -1
- 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/binary.rb +6 -7
- data/lib/arel/nodes/bound_sql_literal.rb +65 -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/{and.rb → nary.rb} +9 -2
- data/lib/arel/nodes/node.rb +115 -5
- 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 +13 -0
- data/lib/arel/nodes/table_alias.rb +4 -0
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +7 -2
- data/lib/arel/predications.rb +14 -4
- data/lib/arel/select_manager.rb +11 -5
- data/lib/arel/table.rb +9 -6
- data/lib/arel/tree_manager.rb +8 -15
- data/lib/arel/update_manager.rb +20 -5
- data/lib/arel/visitors/dot.rb +81 -90
- data/lib/arel/visitors/mysql.rb +23 -5
- data/lib/arel/visitors/postgresql.rb +1 -22
- data/lib/arel/visitors/sqlite.rb +25 -0
- data/lib/arel/visitors/to_sql.rb +170 -36
- data/lib/arel/visitors/visitor.rb +2 -2
- data/lib/arel.rb +23 -4
- 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/templates/create_table_migration.rb.tt +4 -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 +103 -17
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
- data/lib/active_record/null_relation.rb +0 -67
@@ -7,24 +7,78 @@ require "active_record/database_configurations/url_config"
|
|
7
7
|
require "active_record/database_configurations/connection_url_resolver"
|
8
8
|
|
9
9
|
module ActiveRecord
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# = Active Record Database Configurations
|
11
|
+
#
|
12
|
+
# +ActiveRecord::DatabaseConfigurations+ returns an array of +DatabaseConfig+
|
13
|
+
# objects that are constructed from the application's database
|
14
|
+
# configuration hash or URL string.
|
15
|
+
#
|
16
|
+
# The array of +DatabaseConfig+ objects in an application default to either a
|
17
|
+
# HashConfig or UrlConfig. You can retrieve your application's config by using
|
18
|
+
# ActiveRecord::Base.configurations.
|
19
|
+
#
|
20
|
+
# If you register a custom handler, objects will be created according to the
|
21
|
+
# conditions of the handler. See ::register_db_config_handler for more on
|
22
|
+
# registering custom handlers.
|
13
23
|
class DatabaseConfigurations
|
14
24
|
class InvalidConfigurationError < StandardError; end
|
15
25
|
|
16
26
|
attr_reader :configurations
|
17
27
|
delegate :any?, to: :configurations
|
18
28
|
|
29
|
+
singleton_class.attr_accessor :db_config_handlers # :nodoc:
|
30
|
+
self.db_config_handlers = [] # :nodoc:
|
31
|
+
|
32
|
+
# Allows an application to register a custom handler for database configuration
|
33
|
+
# objects. This is useful for creating a custom handler that responds to
|
34
|
+
# methods your application needs but Active Record doesn't implement. For
|
35
|
+
# example if you are using Vitess, you may want your Vitess configurations
|
36
|
+
# to respond to `sharded?`. To implement this define the following in an
|
37
|
+
# initializer:
|
38
|
+
#
|
39
|
+
# ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
|
40
|
+
# next unless config.key?(:vitess)
|
41
|
+
# VitessConfig.new(env_name, name, config)
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# Note: applications must handle the condition in which custom config should be
|
45
|
+
# created in your handler registration otherwise all objects will use the custom
|
46
|
+
# handler.
|
47
|
+
#
|
48
|
+
# Then define your +VitessConfig+ to respond to the methods your application
|
49
|
+
# needs. It is recommended that you inherit from one of the existing
|
50
|
+
# database config classes to avoid having to reimplement all methods. Custom
|
51
|
+
# config handlers should only implement methods Active Record does not.
|
52
|
+
#
|
53
|
+
# class VitessConfig < ActiveRecord::DatabaseConfigurations::UrlConfig
|
54
|
+
# def sharded?
|
55
|
+
# configuration_hash.fetch("sharded", false)
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# For configs that have a +:vitess+ key, a +VitessConfig+ object will be
|
60
|
+
# created instead of a +UrlConfig+.
|
61
|
+
def self.register_db_config_handler(&block)
|
62
|
+
db_config_handlers << block
|
63
|
+
end
|
64
|
+
|
65
|
+
register_db_config_handler do |env_name, name, url, config|
|
66
|
+
if url
|
67
|
+
UrlConfig.new(env_name, name, url, config)
|
68
|
+
else
|
69
|
+
HashConfig.new(env_name, name, config)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
19
73
|
def initialize(configurations = {})
|
20
74
|
@configurations = build_configs(configurations)
|
21
75
|
end
|
22
76
|
|
23
77
|
# Collects the configs for the environment and optionally the specification
|
24
|
-
# name passed in. To include replica configurations pass <tt>
|
78
|
+
# name passed in. To include replica configurations pass <tt>include_hidden: true</tt>.
|
25
79
|
#
|
26
|
-
# If a name is provided a single DatabaseConfig object will be
|
27
|
-
# returned, otherwise an array of DatabaseConfig objects will be
|
80
|
+
# If a name is provided a single +DatabaseConfig+ object will be
|
81
|
+
# returned, otherwise an array of +DatabaseConfig+ objects will be
|
28
82
|
# returned that corresponds with the environment and type requested.
|
29
83
|
#
|
30
84
|
# ==== Options
|
@@ -34,58 +88,49 @@ module ActiveRecord
|
|
34
88
|
# * <tt>name:</tt> The db config name (i.e. primary, animals, etc.). Defaults
|
35
89
|
# to +nil+. If no +env_name+ is specified the config for the default env and the
|
36
90
|
# passed +name+ will be returned.
|
37
|
-
# * <tt>
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
91
|
+
# * <tt>config_key:</tt> Selects configs that contain a particular key in the configuration
|
92
|
+
# hash. Useful for selecting configs that use a custom db config handler or finding
|
93
|
+
# configs with hashes that contain a particular key.
|
94
|
+
# * <tt>include_hidden:</tt> Determines whether to include replicas and configurations
|
95
|
+
# hidden by <tt>database_tasks: false</tt> in the returned list. Most of the time we're only
|
96
|
+
# iterating over the primary connections (i.e. migrations don't need to run for the
|
97
|
+
# write and read connection). Defaults to +false+.
|
98
|
+
def configs_for(env_name: nil, name: nil, config_key: nil, include_hidden: false)
|
47
99
|
env_name ||= default_env if name
|
48
100
|
configs = env_with_configs(env_name)
|
49
101
|
|
50
|
-
unless
|
102
|
+
unless include_hidden
|
103
|
+
configs = configs.select do |db_config|
|
104
|
+
db_config.database_tasks?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if config_key
|
51
109
|
configs = configs.select do |db_config|
|
52
|
-
|
110
|
+
db_config.configuration_hash.key?(config_key)
|
53
111
|
end
|
54
112
|
end
|
55
113
|
|
56
114
|
if name
|
57
115
|
configs.find do |db_config|
|
58
|
-
db_config.name == name
|
116
|
+
db_config.name == name.to_s
|
59
117
|
end
|
60
118
|
else
|
61
119
|
configs
|
62
120
|
end
|
63
121
|
end
|
64
122
|
|
65
|
-
# Returns
|
66
|
-
#
|
67
|
-
# If the application has multiple databases +default_hash+ will
|
68
|
-
# return the first config hash for the environment.
|
69
|
-
#
|
70
|
-
# { database: "my_db", adapter: "mysql2" }
|
71
|
-
def default_hash(env = default_env)
|
72
|
-
default = find_db_config(env)
|
73
|
-
default.configuration_hash if default
|
74
|
-
end
|
75
|
-
alias :[] :default_hash
|
76
|
-
deprecate "[]": "Use configs_for", default_hash: "Use configs_for"
|
77
|
-
|
78
|
-
# Returns a single DatabaseConfig object based on the requested environment.
|
123
|
+
# Returns a single +DatabaseConfig+ object based on the requested environment.
|
79
124
|
#
|
80
125
|
# If the application has multiple databases +find_db_config+ will return
|
81
|
-
# the first DatabaseConfig for the environment.
|
126
|
+
# the first +DatabaseConfig+ for the environment.
|
82
127
|
def find_db_config(env)
|
83
|
-
|
84
|
-
|
85
|
-
.
|
86
|
-
|
87
|
-
|
88
|
-
|
128
|
+
env = env.to_s
|
129
|
+
configurations.find do |db_config|
|
130
|
+
db_config.for_current_env? && (db_config.env_name == env || db_config.name == env)
|
131
|
+
end || configurations.find do |db_config|
|
132
|
+
db_config.env_name == env
|
133
|
+
end
|
89
134
|
end
|
90
135
|
|
91
136
|
# A primary configuration is one that is named primary or if there is
|
@@ -101,17 +146,7 @@ module ActiveRecord
|
|
101
146
|
first_config && name == first_config.name
|
102
147
|
end
|
103
148
|
|
104
|
-
# Returns the DatabaseConfigurations object as a Hash.
|
105
|
-
def to_h
|
106
|
-
configurations.inject({}) do |memo, db_config|
|
107
|
-
memo.merge(db_config.env_name => db_config.configuration_hash.stringify_keys)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
deprecate to_h: "You can use `ActiveRecord::Base.configurations.configs_for(env_name: 'env', name: 'primary').configuration_hash` to get the configuration hashes."
|
111
|
-
|
112
149
|
# Checks if the application's configurations are empty.
|
113
|
-
#
|
114
|
-
# Aliased to blank?
|
115
150
|
def empty?
|
116
151
|
configurations.empty?
|
117
152
|
end
|
@@ -167,7 +202,7 @@ module ActiveRecord
|
|
167
202
|
return configs if configs.is_a?(Array)
|
168
203
|
|
169
204
|
db_configs = configs.flat_map do |env_name, config|
|
170
|
-
if config.is_a?(Hash) && config.all?
|
205
|
+
if config.is_a?(Hash) && config.values.all?(Hash)
|
171
206
|
walk_configs(env_name.to_s, config)
|
172
207
|
else
|
173
208
|
build_db_config_from_raw_config(env_name.to_s, "primary", config)
|
@@ -194,7 +229,7 @@ module ActiveRecord
|
|
194
229
|
raise AdapterNotSpecified, <<~MSG
|
195
230
|
The `#{name}` database is not configured for the `#{default_env}` environment.
|
196
231
|
|
197
|
-
Available
|
232
|
+
Available database configurations are:
|
198
233
|
|
199
234
|
#{build_configuration_sentence}
|
200
235
|
MSG
|
@@ -202,7 +237,7 @@ module ActiveRecord
|
|
202
237
|
end
|
203
238
|
|
204
239
|
def build_configuration_sentence
|
205
|
-
configs = configs_for(
|
240
|
+
configs = configs_for(include_hidden: true)
|
206
241
|
|
207
242
|
configs.group_by(&:env_name).map do |env, config|
|
208
243
|
names = config.map(&:name)
|
@@ -236,15 +271,16 @@ module ActiveRecord
|
|
236
271
|
end
|
237
272
|
|
238
273
|
def build_db_config_from_hash(env_name, name, config)
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
config_without_url.delete :url
|
274
|
+
url = config[:url]
|
275
|
+
config_without_url = config.dup
|
276
|
+
config_without_url.delete :url
|
243
277
|
|
244
|
-
|
245
|
-
|
246
|
-
|
278
|
+
DatabaseConfigurations.db_config_handlers.reverse_each do |handler|
|
279
|
+
config = handler.call(env_name, name, url, config_without_url)
|
280
|
+
return config if config
|
247
281
|
end
|
282
|
+
|
283
|
+
nil
|
248
284
|
end
|
249
285
|
|
250
286
|
def merge_db_environment_variables(current_env, configs)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "active_support/core_ext/string/inquiry"
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
|
-
#
|
6
|
+
# = Delegated types
|
7
7
|
#
|
8
8
|
# Class hierarchies can map to relational database tables in many ways. Active Record, for example, offers
|
9
9
|
# purely abstract classes, where the superclass doesn't persist any attributes, and single-table inheritance,
|
@@ -36,7 +36,7 @@ module ActiveRecord
|
|
36
36
|
#
|
37
37
|
# Let's look at that entry/message/comment example using delegated types:
|
38
38
|
#
|
39
|
-
# # Schema: entries[ id, account_id, creator_id,
|
39
|
+
# # Schema: entries[ id, account_id, creator_id, entryable_type, entryable_id, created_at, updated_at ]
|
40
40
|
# class Entry < ApplicationRecord
|
41
41
|
# belongs_to :account
|
42
42
|
# belongs_to :creator
|
@@ -51,13 +51,12 @@ module ActiveRecord
|
|
51
51
|
# end
|
52
52
|
# end
|
53
53
|
#
|
54
|
-
# # Schema: messages[ id, subject ]
|
54
|
+
# # Schema: messages[ id, subject, body, created_at, updated_at ]
|
55
55
|
# class Message < ApplicationRecord
|
56
56
|
# include Entryable
|
57
|
-
# has_rich_text :content
|
58
57
|
# end
|
59
58
|
#
|
60
|
-
# # Schema: comments[ id, content ]
|
59
|
+
# # Schema: comments[ id, content, created_at, updated_at ]
|
61
60
|
# class Comment < ApplicationRecord
|
62
61
|
# include Entryable
|
63
62
|
# end
|
@@ -66,7 +65,7 @@ module ActiveRecord
|
|
66
65
|
# resides in the +Entry+ "superclass". But the +Entry+ absolutely can stand alone in terms of querying capacity
|
67
66
|
# in particular. You can now easily do things like:
|
68
67
|
#
|
69
|
-
# Account.entries.order(created_at: :desc).limit(50)
|
68
|
+
# Account.find(1).entries.order(created_at: :desc).limit(50)
|
70
69
|
#
|
71
70
|
# Which is exactly what you want when displaying both comments and messages together. The entry itself can
|
72
71
|
# be rendered as its delegated type easily, like so:
|
@@ -76,7 +75,9 @@ module ActiveRecord
|
|
76
75
|
#
|
77
76
|
# # entries/entryables/_message.html.erb
|
78
77
|
# <div class="message">
|
79
|
-
#
|
78
|
+
# <div class="subject"><%= entry.message.subject %></div>
|
79
|
+
# <p><%= entry.message.body %></p>
|
80
|
+
# <i>Posted on <%= entry.created_at %> by <%= entry.creator.name %></i>
|
80
81
|
# </div>
|
81
82
|
#
|
82
83
|
# # entries/entryables/_comment.html.erb
|
@@ -101,17 +102,37 @@ module ActiveRecord
|
|
101
102
|
# You create a new record that uses delegated typing by creating the delegator and delegatee at the same time,
|
102
103
|
# like so:
|
103
104
|
#
|
104
|
-
# Entry.create! entryable: Comment.new(content: "Hello!"), creator: Current.user
|
105
|
+
# Entry.create! entryable: Comment.new(content: "Hello!"), creator: Current.user, account: Current.account
|
105
106
|
#
|
106
107
|
# If you need more complicated composition, or you need to perform dependent validation, you should build a factory
|
107
108
|
# method or class to take care of the complicated needs. This could be as simple as:
|
108
109
|
#
|
109
110
|
# class Entry < ApplicationRecord
|
110
|
-
# def self.create_with_comment(content, creator: Current.user)
|
111
|
-
# create! entryable: Comment.new(content: content), creator: creator
|
111
|
+
# def self.create_with_comment(content, creator: Current.user, account: Current.account)
|
112
|
+
# create! entryable: Comment.new(content: content), creator: creator, account: account
|
112
113
|
# end
|
113
114
|
# end
|
114
115
|
#
|
116
|
+
# == Querying across records
|
117
|
+
#
|
118
|
+
# A consequence of delegated types is that querying attributes spread across multiple classes becomes slightly more
|
119
|
+
# tricky, but not impossible.
|
120
|
+
#
|
121
|
+
# The simplest method is to join the "superclass" to the "subclass" and apply the query parameters (i.e. <tt>#where</tt>)
|
122
|
+
# in appropriate places:
|
123
|
+
#
|
124
|
+
# Comment.joins(:entry).where(comments: { content: 'Hello!' }, entry: { creator: Current.user } )
|
125
|
+
#
|
126
|
+
# For convenience, add a scope on the concern. Now all classes that implement the concern will automatically include
|
127
|
+
# the method:
|
128
|
+
#
|
129
|
+
# # app/models/concerns/entryable.rb
|
130
|
+
# scope :with_entry, ->(attrs) { joins(:entry).where(entry: attrs) }
|
131
|
+
#
|
132
|
+
# Now the query can be shortened significantly:
|
133
|
+
#
|
134
|
+
# Comment.where(content: 'Hello!').with_entry(creator: Current.user)
|
135
|
+
#
|
115
136
|
# == Adding further delegation
|
116
137
|
#
|
117
138
|
# The delegated type shouldn't just answer the question of what the underlying class is called. In fact, that's
|
@@ -135,7 +156,22 @@ module ActiveRecord
|
|
135
156
|
# end
|
136
157
|
# end
|
137
158
|
#
|
138
|
-
# Now you can list a bunch of entries, call
|
159
|
+
# Now you can list a bunch of entries, call <tt>Entry#title</tt>, and polymorphism will provide you with the answer.
|
160
|
+
#
|
161
|
+
# == Nested \Attributes
|
162
|
+
#
|
163
|
+
# Enabling nested attributes on a delegated_type association allows you to
|
164
|
+
# create the entry and message in one go:
|
165
|
+
#
|
166
|
+
# class Entry < ApplicationRecord
|
167
|
+
# delegated_type :entryable, types: %w[ Message Comment ]
|
168
|
+
# accepts_nested_attributes_for :entryable
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# params = { entry: { entryable_type: 'Message', entryable_attributes: { subject: 'Smiling' } } }
|
172
|
+
# entry = Entry.create(params[:entry])
|
173
|
+
# entry.entryable.id # => 2
|
174
|
+
# entry.entryable.subject # => 'Smiling'
|
139
175
|
module DelegatedType
|
140
176
|
# Defines this as a class that'll delegate its type for the passed +role+ to the class references in +types+.
|
141
177
|
# That'll create a polymorphic +belongs_to+ relationship to that +role+, and it'll add all the delegated
|
@@ -156,8 +192,6 @@ module ActiveRecord
|
|
156
192
|
# Entry#comment # => returns the comment record, when entryable_type == "Comment", otherwise nil
|
157
193
|
# Entry#comment_id # => returns entryable_id, when entryable_type == "Comment", otherwise nil
|
158
194
|
#
|
159
|
-
# The +options+ are passed directly to the +belongs_to+ call, so this is where you declare +dependent+ etc.
|
160
|
-
#
|
161
195
|
# You can also declare namespaced types:
|
162
196
|
#
|
163
197
|
# class Entry < ApplicationRecord
|
@@ -167,26 +201,62 @@ module ActiveRecord
|
|
167
201
|
# Entry.access_notice_messages
|
168
202
|
# entry.access_notice_message
|
169
203
|
# entry.access_notice_message?
|
204
|
+
#
|
205
|
+
# === Options
|
206
|
+
#
|
207
|
+
# The +options+ are passed directly to the +belongs_to+ call, so this is where you declare +dependent+ etc.
|
208
|
+
# The following options can be included to specialize the behavior of the delegated type convenience methods.
|
209
|
+
#
|
210
|
+
# [:foreign_key]
|
211
|
+
# Specify the foreign key used for the convenience methods. By default this is guessed to be the passed
|
212
|
+
# +role+ with an "_id" suffix. So a class that defines a
|
213
|
+
# <tt>delegated_type :entryable, types: %w[ Message Comment ]</tt> association will use "entryable_id" as
|
214
|
+
# the default <tt>:foreign_key</tt>.
|
215
|
+
# [:foreign_type]
|
216
|
+
# Specify the column used to store the associated object's type. By default this is inferred to be the passed
|
217
|
+
# +role+ with a "_type" suffix. A class that defines a
|
218
|
+
# <tt>delegated_type :entryable, types: %w[ Message Comment ]</tt> association will use "entryable_type" as
|
219
|
+
# the default <tt>:foreign_type</tt>.
|
220
|
+
# [:primary_key]
|
221
|
+
# Specify the method that returns the primary key of associated object used for the convenience methods.
|
222
|
+
# By default this is +id+.
|
223
|
+
#
|
224
|
+
# Option examples:
|
225
|
+
# class Entry < ApplicationRecord
|
226
|
+
# delegated_type :entryable, types: %w[ Message Comment ], primary_key: :uuid, foreign_key: :entryable_uuid
|
227
|
+
# end
|
228
|
+
#
|
229
|
+
# Entry#message_uuid # => returns entryable_uuid, when entryable_type == "Message", otherwise nil
|
230
|
+
# Entry#comment_uuid # => returns entryable_uuid, when entryable_type == "Comment", otherwise nil
|
170
231
|
def delegated_type(role, types:, **options)
|
171
232
|
belongs_to role, options.delete(:scope), **options.merge(polymorphic: true)
|
172
|
-
define_delegated_type_methods role, types: types
|
233
|
+
define_delegated_type_methods role, types: types, options: options
|
173
234
|
end
|
174
235
|
|
175
236
|
private
|
176
|
-
def define_delegated_type_methods(role, types:)
|
177
|
-
|
178
|
-
|
237
|
+
def define_delegated_type_methods(role, types:, options:)
|
238
|
+
primary_key = options[:primary_key] || "id"
|
239
|
+
role_type = options[:foreign_type] || "#{role}_type"
|
240
|
+
role_id = options[:foreign_key] || "#{role}_id"
|
241
|
+
|
242
|
+
define_singleton_method "#{role}_types" do
|
243
|
+
types.map(&:to_s)
|
244
|
+
end
|
179
245
|
|
180
246
|
define_method "#{role}_class" do
|
181
|
-
public_send(
|
247
|
+
public_send(role_type).constantize
|
182
248
|
end
|
183
249
|
|
184
250
|
define_method "#{role}_name" do
|
185
251
|
public_send("#{role}_class").model_name.singular.inquiry
|
186
252
|
end
|
187
253
|
|
254
|
+
define_method "build_#{role}" do |*params|
|
255
|
+
public_send("#{role}=", public_send("#{role}_class").new(*params))
|
256
|
+
end
|
257
|
+
|
188
258
|
types.each do |type|
|
189
|
-
scope_name = type.tableize.
|
259
|
+
scope_name = type.tableize.tr("/", "_")
|
190
260
|
singular = scope_name.singularize
|
191
261
|
query = "#{singular}?"
|
192
262
|
|
@@ -200,7 +270,7 @@ module ActiveRecord
|
|
200
270
|
public_send(role) if public_send(query)
|
201
271
|
end
|
202
272
|
|
203
|
-
define_method "#{singular}
|
273
|
+
define_method "#{singular}_#{primary_key}" do
|
204
274
|
public_send(role_id) if public_send(query)
|
205
275
|
end
|
206
276
|
end
|
@@ -4,9 +4,11 @@ module ActiveRecord
|
|
4
4
|
class DestroyAssociationAsyncError < StandardError
|
5
5
|
end
|
6
6
|
|
7
|
+
# = Active Record Destroy Association Async Job
|
8
|
+
#
|
7
9
|
# Job to destroy the records associated with a destroyed record in background.
|
8
10
|
class DestroyAssociationAsyncJob < ActiveJob::Base
|
9
|
-
queue_as { ActiveRecord
|
11
|
+
queue_as { ActiveRecord.queues[:destroy] }
|
10
12
|
|
11
13
|
discard_on ActiveJob::DeserializationError
|
12
14
|
|
@@ -17,7 +19,7 @@ module ActiveRecord
|
|
17
19
|
)
|
18
20
|
association_model = association_class.constantize
|
19
21
|
owner_class = owner_model_name.constantize
|
20
|
-
owner = owner_class.find_by(owner_class.primary_key
|
22
|
+
owner = owner_class.find_by(owner_class.primary_key => [owner_id])
|
21
23
|
|
22
24
|
if !owner_destroyed?(owner, ensuring_owner_was_method)
|
23
25
|
raise DestroyAssociationAsyncError, "owner record not destroyed"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class DisableJoinsAssociationRelation < Relation # :nodoc:
|
5
|
+
attr_reader :ids, :key
|
6
|
+
|
7
|
+
def initialize(klass, key, ids)
|
8
|
+
@ids = ids.uniq
|
9
|
+
@key = key
|
10
|
+
super(klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
def limit(value)
|
14
|
+
records.take(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def first(limit = nil)
|
18
|
+
if limit
|
19
|
+
records.limit(limit).first
|
20
|
+
else
|
21
|
+
records.first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def load
|
26
|
+
super
|
27
|
+
records = @records
|
28
|
+
|
29
|
+
records_by_id = records.group_by do |record|
|
30
|
+
record[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
records = ids.flat_map { |id| records_by_id[id] }
|
34
|
+
records.compact!
|
35
|
+
|
36
|
+
@records = records
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
|
-
module DynamicMatchers
|
4
|
+
module DynamicMatchers # :nodoc:
|
5
5
|
private
|
6
6
|
def respond_to_missing?(name, _)
|
7
7
|
if self == Base
|
@@ -12,12 +12,12 @@ module ActiveRecord
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def method_missing(name,
|
15
|
+
def method_missing(name, ...)
|
16
16
|
match = Method.match(self, name)
|
17
17
|
|
18
18
|
if match && match.valid?
|
19
19
|
match.define
|
20
|
-
send(name,
|
20
|
+
send(name, ...)
|
21
21
|
else
|
22
22
|
super
|
23
23
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Encryption
|
5
|
+
class AutoFilteredParameters
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
@attributes_by_class = Concurrent::Map.new
|
9
|
+
@collecting = true
|
10
|
+
|
11
|
+
install_collecting_hook
|
12
|
+
end
|
13
|
+
|
14
|
+
def enable
|
15
|
+
apply_collected_attributes
|
16
|
+
@collecting = false
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
attr_reader :app
|
21
|
+
|
22
|
+
def install_collecting_hook
|
23
|
+
ActiveRecord::Encryption.on_encrypted_attribute_declared do |klass, attribute|
|
24
|
+
attribute_was_declared(klass, attribute)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def attribute_was_declared(klass, attribute)
|
29
|
+
if collecting?
|
30
|
+
collect_for_later(klass, attribute)
|
31
|
+
else
|
32
|
+
apply_filter(klass, attribute)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def apply_collected_attributes
|
37
|
+
@attributes_by_class.each do |klass, attributes|
|
38
|
+
attributes.each do |attribute|
|
39
|
+
apply_filter(klass, attribute)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def collecting?
|
45
|
+
@collecting
|
46
|
+
end
|
47
|
+
|
48
|
+
def collect_for_later(klass, attribute)
|
49
|
+
@attributes_by_class[klass] ||= Concurrent::Array.new
|
50
|
+
@attributes_by_class[klass] << attribute
|
51
|
+
end
|
52
|
+
|
53
|
+
def apply_filter(klass, attribute)
|
54
|
+
filter = [("#{klass.model_name.element}" if klass.name), attribute.to_s].compact.join(".")
|
55
|
+
unless excluded_from_filter_parameters?(filter)
|
56
|
+
app.config.filter_parameters << filter unless app.config.filter_parameters.include?(filter)
|
57
|
+
klass.filter_attributes += [ attribute ]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def excluded_from_filter_parameters?(filter_parameter)
|
62
|
+
ActiveRecord::Encryption.config.excluded_from_filter_parameters.find { |excluded_filter| excluded_filter.to_s == filter_parameter }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|