activerecord 6.1.7.4 → 7.0.6
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 +1449 -1014
- data/README.rdoc +3 -3
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/association_relation.rb +0 -10
- data/lib/active_record/associations/association.rb +33 -17
- data/lib/active_record/associations/association_scope.rb +1 -3
- data/lib/active_record/associations/belongs_to_association.rb +15 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +8 -2
- data/lib/active_record/associations/builder/belongs_to.rb +19 -6
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- 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 +2 -2
- data/lib/active_record/associations/collection_association.rb +19 -21
- data/lib/active_record/associations/collection_proxy.rb +10 -5
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/has_many_association.rb +8 -5
- data/lib/active_record/associations/has_many_through_association.rb +2 -1
- data/lib/active_record/associations/has_one_association.rb +14 -7
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +23 -15
- data/lib/active_record/associations/preloader/association.rb +186 -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 +39 -113
- data/lib/active_record/associations/singular_association.rb +15 -7
- data/lib/active_record/associations/through_association.rb +3 -3
- data/lib/active_record/associations.rb +138 -100
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
- data/lib/active_record/attribute_methods/dirty.rb +49 -16
- data/lib/active_record/attribute_methods/primary_key.rb +2 -2
- data/lib/active_record/attribute_methods/query.rb +2 -2
- data/lib/active_record/attribute_methods/read.rb +8 -6
- data/lib/active_record/attribute_methods/serialization.rb +57 -19
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
- data/lib/active_record/attribute_methods/write.rb +7 -10
- data/lib/active_record/attribute_methods.rb +19 -22
- data/lib/active_record/attributes.rb +24 -35
- data/lib/active_record/autosave_association.rb +17 -28
- data/lib/active_record/base.rb +19 -1
- data/lib/active_record/callbacks.rb +14 -16
- data/lib/active_record/coders/yaml_column.rb +4 -8
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +292 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +47 -561
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +0 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +46 -22
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -12
- data/lib/active_record/connection_adapters/abstract/quoting.rb +42 -72
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -17
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +52 -23
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +82 -25
- data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -22
- data/lib/active_record/connection_adapters/abstract_adapter.rb +153 -74
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +112 -84
- data/lib/active_record/connection_adapters/column.rb +4 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +36 -24
- data/lib/active_record/connection_adapters/mysql/quoting.rb +45 -21
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +4 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +7 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +20 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -6
- data/lib/active_record/connection_adapters/pool_config.rb +7 -7
- data/lib/active_record/connection_adapters/postgresql/column.rb +19 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +20 -17
- 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/range.rb +1 -1
- 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 +71 -71
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +34 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +21 -1
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +22 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +40 -21
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +207 -106
- data/lib/active_record/connection_adapters/schema_cache.rb +39 -38
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +25 -19
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +28 -16
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +17 -15
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +97 -32
- data/lib/active_record/connection_adapters.rb +6 -5
- data/lib/active_record/connection_handling.rb +49 -55
- data/lib/active_record/core.rb +123 -148
- data/lib/active_record/database_configurations/connection_url_resolver.rb +2 -1
- data/lib/active_record/database_configurations/database_config.rb +12 -9
- data/lib/active_record/database_configurations/hash_config.rb +63 -5
- data/lib/active_record/database_configurations/url_config.rb +2 -2
- data/lib/active_record/database_configurations.rb +15 -32
- data/lib/active_record/delegated_type.rb +53 -12
- data/lib/active_record/destroy_association_async_job.rb +1 -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/cipher/aes256_gcm.rb +98 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +44 -0
- data/lib/active_record/encryption/configurable.rb +67 -0
- data/lib/active_record/encryption/context.rb +35 -0
- data/lib/active_record/encryption/contexts.rb +72 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +206 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -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 +160 -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 +42 -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 +90 -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 +99 -0
- data/lib/active_record/encryption.rb +55 -0
- data/lib/active_record/enum.rb +50 -43
- data/lib/active_record/errors.rb +67 -4
- 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/table_row.rb +41 -6
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +20 -23
- data/lib/active_record/future_result.rb +139 -0
- data/lib/active_record/gem_version.rb +5 -5
- data/lib/active_record/inheritance.rb +55 -17
- data/lib/active_record/insert_all.rb +80 -14
- data/lib/active_record/integration.rb +4 -3
- data/lib/active_record/internal_metadata.rb +1 -5
- 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 +10 -4
- data/lib/active_record/log_subscriber.rb +23 -7
- data/lib/active_record/middleware/database_selector/resolver.rb +6 -10
- data/lib/active_record/middleware/database_selector.rb +18 -6
- data/lib/active_record/middleware/shard_selector.rb +60 -0
- data/lib/active_record/migration/command_recorder.rb +8 -9
- data/lib/active_record/migration/compatibility.rb +91 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +115 -84
- data/lib/active_record/model_schema.rb +58 -59
- data/lib/active_record/nested_attributes.rb +13 -12
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/null_relation.rb +2 -6
- data/lib/active_record/persistence.rb +228 -60
- data/lib/active_record/query_cache.rb +2 -2
- data/lib/active_record/query_logs.rb +149 -0
- data/lib/active_record/querying.rb +16 -6
- data/lib/active_record/railtie.rb +136 -22
- data/lib/active_record/railties/controller_runtime.rb +1 -1
- data/lib/active_record/railties/databases.rake +78 -136
- data/lib/active_record/readonly_attributes.rb +11 -0
- data/lib/active_record/reflection.rb +80 -49
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +6 -6
- data/lib/active_record/relation/calculations.rb +92 -60
- data/lib/active_record/relation/delegation.rb +7 -7
- data/lib/active_record/relation/finder_methods.rb +31 -35
- data/lib/active_record/relation/merger.rb +20 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +20 -1
- data/lib/active_record/relation/predicate_builder.rb +2 -6
- data/lib/active_record/relation/query_attribute.rb +5 -11
- data/lib/active_record/relation/query_methods.rb +285 -68
- data/lib/active_record/relation/record_fetch_warning.rb +7 -9
- data/lib/active_record/relation/spawn_methods.rb +2 -2
- data/lib/active_record/relation/where_clause.rb +10 -19
- data/lib/active_record/relation.rb +189 -88
- data/lib/active_record/result.rb +23 -11
- data/lib/active_record/runtime_registry.rb +9 -13
- data/lib/active_record/sanitization.rb +17 -12
- data/lib/active_record/schema.rb +38 -23
- data/lib/active_record/schema_dumper.rb +29 -19
- data/lib/active_record/schema_migration.rb +4 -4
- data/lib/active_record/scoping/default.rb +60 -13
- data/lib/active_record/scoping/named.rb +3 -11
- data/lib/active_record/scoping.rb +64 -34
- data/lib/active_record/serialization.rb +6 -1
- data/lib/active_record/signed_id.rb +3 -3
- data/lib/active_record/store.rb +2 -2
- data/lib/active_record/suppressor.rb +11 -15
- data/lib/active_record/table_metadata.rb +5 -1
- data/lib/active_record/tasks/database_tasks.rb +127 -60
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -13
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +9 -6
- data/lib/active_record/timestamp.rb +3 -4
- data/lib/active_record/transactions.rb +9 -14
- data/lib/active_record/translation.rb +3 -3
- data/lib/active_record/type/adapter_specific_registry.rb +32 -7
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +2 -2
- data/lib/active_record/type/serialized.rb +5 -5
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/validations/associated.rb +4 -4
- data/lib/active_record/validations/presence.rb +2 -2
- data/lib/active_record/validations/uniqueness.rb +4 -4
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +225 -27
- 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/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/delete_statement.rb +12 -13
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/predications.rb +11 -3
- data/lib/arel/select_manager.rb +10 -4
- data/lib/arel/table.rb +0 -1
- 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 +8 -2
- data/lib/arel/visitors/postgresql.rb +0 -10
- data/lib/arel/visitors/to_sql.rb +58 -2
- data/lib/arel.rb +2 -1
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- 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 +58 -14
@@ -4,7 +4,7 @@ module ActiveRecord
|
|
4
4
|
# See ActiveRecord::Transactions::ClassMethods for documentation.
|
5
5
|
module Transactions
|
6
6
|
extend ActiveSupport::Concern
|
7
|
-
|
7
|
+
# :nodoc:
|
8
8
|
ACTIONS = [:create, :destroy, :update]
|
9
9
|
|
10
10
|
included do
|
@@ -290,19 +290,19 @@ module ActiveRecord
|
|
290
290
|
self.class.transaction(**options, &block)
|
291
291
|
end
|
292
292
|
|
293
|
-
def destroy
|
293
|
+
def destroy # :nodoc:
|
294
294
|
with_transaction_returning_status { super }
|
295
295
|
end
|
296
296
|
|
297
|
-
def save(**)
|
297
|
+
def save(**) # :nodoc:
|
298
298
|
with_transaction_returning_status { super }
|
299
299
|
end
|
300
300
|
|
301
|
-
def save!(**)
|
301
|
+
def save!(**) # :nodoc:
|
302
302
|
with_transaction_returning_status { super }
|
303
303
|
end
|
304
304
|
|
305
|
-
def touch(*, **)
|
305
|
+
def touch(*, **) # :nodoc:
|
306
306
|
with_transaction_returning_status { super }
|
307
307
|
end
|
308
308
|
|
@@ -314,8 +314,8 @@ module ActiveRecord
|
|
314
314
|
#
|
315
315
|
# Ensure that it is not called if the object was never persisted (failed create),
|
316
316
|
# but call it after the commit of a destroyed object.
|
317
|
-
def committed!(should_run_callbacks: true)
|
318
|
-
|
317
|
+
def committed!(should_run_callbacks: true) # :nodoc:
|
318
|
+
@_start_transaction_state = nil
|
319
319
|
if should_run_callbacks
|
320
320
|
@_committed_already_called = true
|
321
321
|
_run_commit_callbacks
|
@@ -326,7 +326,7 @@ module ActiveRecord
|
|
326
326
|
|
327
327
|
# Call the #after_rollback callbacks. The +force_restore_state+ argument indicates if the record
|
328
328
|
# state should be rolled back to the beginning or just to the last savepoint.
|
329
|
-
def rolledback!(force_restore_state: false, should_run_callbacks: true)
|
329
|
+
def rolledback!(force_restore_state: false, should_run_callbacks: true) # :nodoc:
|
330
330
|
if should_run_callbacks
|
331
331
|
_run_rollback_callbacks
|
332
332
|
end
|
@@ -389,12 +389,7 @@ module ActiveRecord
|
|
389
389
|
def clear_transaction_record_state
|
390
390
|
return unless @_start_transaction_state
|
391
391
|
@_start_transaction_state[:level] -= 1
|
392
|
-
|
393
|
-
end
|
394
|
-
|
395
|
-
# Force to clear the transaction record state.
|
396
|
-
def force_clear_transaction_record_state
|
397
|
-
@_start_transaction_state = nil
|
392
|
+
@_start_transaction_state = nil if @_start_transaction_state[:level] < 1
|
398
393
|
end
|
399
394
|
|
400
395
|
# Restore the new record state and id of a record that was previously saved by a call to save_record_state.
|
@@ -5,7 +5,7 @@ module ActiveRecord
|
|
5
5
|
include ActiveModel::Translation
|
6
6
|
|
7
7
|
# Set the lookup ancestors for ActiveModel.
|
8
|
-
def lookup_ancestors
|
8
|
+
def lookup_ancestors # :nodoc:
|
9
9
|
klass = self
|
10
10
|
classes = [klass]
|
11
11
|
return classes if klass == ActiveRecord::Base
|
@@ -16,8 +16,8 @@ module ActiveRecord
|
|
16
16
|
classes
|
17
17
|
end
|
18
18
|
|
19
|
-
# Set the i18n scope to
|
20
|
-
def i18n_scope
|
19
|
+
# Set the i18n scope to override ActiveModel.
|
20
|
+
def i18n_scope # :nodoc:
|
21
21
|
:activerecord
|
22
22
|
end
|
23
23
|
end
|
@@ -5,15 +5,40 @@ require "active_model/type/registry"
|
|
5
5
|
module ActiveRecord
|
6
6
|
# :stopdoc:
|
7
7
|
module Type
|
8
|
-
class AdapterSpecificRegistry
|
8
|
+
class AdapterSpecificRegistry # :nodoc:
|
9
|
+
def initialize
|
10
|
+
@registrations = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize_copy(other)
|
14
|
+
@registrations = @registrations.dup
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
9
18
|
def add_modifier(options, klass, **args)
|
10
19
|
registrations << DecorationRegistration.new(options, klass, **args)
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
def register(type_name, klass = nil, **options, &block)
|
23
|
+
unless block_given?
|
24
|
+
block = proc { |_, *args| klass.new(*args) }
|
25
|
+
block.ruby2_keywords if block.respond_to?(:ruby2_keywords)
|
16
26
|
end
|
27
|
+
registrations << Registration.new(type_name, block, **options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def lookup(symbol, *args, **kwargs)
|
31
|
+
registration = find_registration(symbol, *args, **kwargs)
|
32
|
+
|
33
|
+
if registration
|
34
|
+
registration.call(self, symbol, *args, **kwargs)
|
35
|
+
else
|
36
|
+
raise ArgumentError, "Unknown type #{symbol.inspect}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
attr_reader :registrations
|
17
42
|
|
18
43
|
def find_registration(symbol, *args, **kwargs)
|
19
44
|
registrations
|
@@ -22,7 +47,7 @@ module ActiveRecord
|
|
22
47
|
end
|
23
48
|
end
|
24
49
|
|
25
|
-
class Registration
|
50
|
+
class Registration # :nodoc:
|
26
51
|
def initialize(name, block, adapter: nil, override: nil)
|
27
52
|
@name = name
|
28
53
|
@block = block
|
@@ -89,7 +114,7 @@ module ActiveRecord
|
|
89
114
|
end
|
90
115
|
end
|
91
116
|
|
92
|
-
class DecorationRegistration < Registration
|
117
|
+
class DecorationRegistration < Registration # :nodoc:
|
93
118
|
def initialize(options, klass, adapter: nil)
|
94
119
|
@options = options
|
95
120
|
@klass = klass
|
@@ -120,7 +145,7 @@ module ActiveRecord
|
|
120
145
|
end
|
121
146
|
end
|
122
147
|
|
123
|
-
class TypeConflictError < StandardError
|
148
|
+
class TypeConflictError < StandardError # :nodoc:
|
124
149
|
end
|
125
150
|
# :startdoc:
|
126
151
|
end
|
@@ -2,7 +2,40 @@
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Type
|
5
|
-
class HashLookupTypeMap
|
5
|
+
class HashLookupTypeMap # :nodoc:
|
6
|
+
def initialize(parent = nil)
|
7
|
+
@mapping = {}
|
8
|
+
@cache = Concurrent::Map.new do |h, key|
|
9
|
+
h.fetch_or_store(key, Concurrent::Map.new)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def lookup(lookup_key, *args)
|
14
|
+
fetch(lookup_key, *args) { Type.default_value }
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(lookup_key, *args, &block)
|
18
|
+
@cache[lookup_key].fetch_or_store(args) do
|
19
|
+
perform_fetch(lookup_key, *args, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_type(key, value = nil, &block)
|
24
|
+
raise ::ArgumentError unless value || block
|
25
|
+
|
26
|
+
if block
|
27
|
+
@mapping[key] = block
|
28
|
+
else
|
29
|
+
@mapping[key] = proc { value }
|
30
|
+
end
|
31
|
+
@cache.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
@mapping.clear
|
36
|
+
@cache.clear
|
37
|
+
end
|
38
|
+
|
6
39
|
def alias_type(type, alias_type)
|
7
40
|
register_type(type) { |_, *args| lookup(alias_type, *args) }
|
8
41
|
end
|
@@ -5,11 +5,11 @@ module ActiveRecord
|
|
5
5
|
module Internal
|
6
6
|
module Timezone
|
7
7
|
def is_utc?
|
8
|
-
ActiveRecord
|
8
|
+
ActiveRecord.default_timezone == :utc
|
9
9
|
end
|
10
10
|
|
11
11
|
def default_timezone
|
12
|
-
ActiveRecord
|
12
|
+
ActiveRecord.default_timezone
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -31,7 +31,7 @@ module ActiveRecord
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def inspect
|
34
|
-
Kernel.instance_method(:inspect).
|
34
|
+
Kernel.instance_method(:inspect).bind_call(self)
|
35
35
|
end
|
36
36
|
|
37
37
|
def changed_in_place?(raw_old_value, value)
|
@@ -63,11 +63,11 @@ module ActiveRecord
|
|
63
63
|
def encoded(value)
|
64
64
|
return if default_value?(value)
|
65
65
|
payload = coder.dump(value)
|
66
|
-
if payload && binary?
|
67
|
-
|
68
|
-
|
66
|
+
if payload && @subtype.binary?
|
67
|
+
ActiveModel::Type::Binary::Data.new(payload)
|
68
|
+
else
|
69
|
+
payload
|
69
70
|
end
|
70
|
-
payload
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -5,55 +5,52 @@ require "concurrent/map"
|
|
5
5
|
module ActiveRecord
|
6
6
|
module Type
|
7
7
|
class TypeMap # :nodoc:
|
8
|
-
def initialize
|
8
|
+
def initialize(parent = nil)
|
9
9
|
@mapping = {}
|
10
|
-
@
|
11
|
-
|
12
|
-
end
|
10
|
+
@parent = parent
|
11
|
+
@cache = Concurrent::Map.new
|
13
12
|
end
|
14
13
|
|
15
|
-
def lookup(lookup_key
|
16
|
-
fetch(lookup_key
|
14
|
+
def lookup(lookup_key)
|
15
|
+
fetch(lookup_key) { Type.default_value }
|
17
16
|
end
|
18
17
|
|
19
|
-
def fetch(lookup_key,
|
20
|
-
@cache
|
21
|
-
perform_fetch(lookup_key,
|
18
|
+
def fetch(lookup_key, &block)
|
19
|
+
@cache.fetch_or_store(lookup_key) do
|
20
|
+
perform_fetch(lookup_key, &block)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
def register_type(key, value = nil, &block)
|
26
25
|
raise ::ArgumentError unless value || block
|
27
|
-
@cache.clear
|
28
26
|
|
29
27
|
if block
|
30
28
|
@mapping[key] = block
|
31
29
|
else
|
32
30
|
@mapping[key] = proc { value }
|
33
31
|
end
|
32
|
+
@cache.clear
|
34
33
|
end
|
35
34
|
|
36
35
|
def alias_type(key, target_key)
|
37
|
-
register_type(key) do |sql_type
|
36
|
+
register_type(key) do |sql_type|
|
38
37
|
metadata = sql_type[/\(.*\)/, 0]
|
39
|
-
lookup("#{target_key}#{metadata}"
|
38
|
+
lookup("#{target_key}#{metadata}")
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def perform_fetch(lookup_key, *args)
|
42
|
+
protected
|
43
|
+
def perform_fetch(lookup_key, &block)
|
49
44
|
matching_pair = @mapping.reverse_each.detect do |key, _|
|
50
45
|
key === lookup_key
|
51
46
|
end
|
52
47
|
|
53
48
|
if matching_pair
|
54
|
-
matching_pair.last.call(lookup_key
|
49
|
+
matching_pair.last.call(lookup_key)
|
50
|
+
elsif @parent
|
51
|
+
@parent.perform_fetch(lookup_key, &block)
|
55
52
|
else
|
56
|
-
yield lookup_key
|
53
|
+
yield lookup_key
|
57
54
|
end
|
58
55
|
end
|
59
56
|
end
|
data/lib/active_record/type.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Validations
|
5
|
-
class AssociatedValidator < ActiveModel::EachValidator
|
5
|
+
class AssociatedValidator < ActiveModel::EachValidator # :nodoc:
|
6
6
|
def validate_each(record, attribute, value)
|
7
7
|
if Array(value).reject { |r| valid_object?(r) }.any?
|
8
8
|
record.errors.add(attribute, :invalid, **options.merge(value: value))
|
@@ -42,14 +42,14 @@ module ActiveRecord
|
|
42
42
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
43
43
|
# <tt>on: :custom_validation_context</tt> or
|
44
44
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
45
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
45
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
46
46
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
47
47
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
48
48
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
49
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
49
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to
|
50
50
|
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
51
51
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
52
|
-
# method, proc or string should return or evaluate to a +true+ or +false+
|
52
|
+
# method, proc, or string should return or evaluate to a +true+ or +false+
|
53
53
|
# value.
|
54
54
|
def validates_associated(*attr_names)
|
55
55
|
validates_with AssociatedValidator, _merge_attributes(attr_names)
|
@@ -50,11 +50,11 @@ module ActiveRecord
|
|
50
50
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
51
51
|
# <tt>on: :custom_validation_context</tt> or
|
52
52
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
53
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
|
53
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine if
|
54
54
|
# the validation should occur (e.g. <tt>if: :allow_validation</tt>, or
|
55
55
|
# <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
|
56
56
|
# or string should return or evaluate to a +true+ or +false+ value.
|
57
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
|
57
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to determine
|
58
58
|
# if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
59
59
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
60
60
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
@@ -161,19 +161,19 @@ module ActiveRecord
|
|
161
161
|
# <tt>WHERE</tt> SQL fragment to limit the uniqueness constraint lookup
|
162
162
|
# (e.g. <tt>conditions: -> { where(status: 'active') }</tt>).
|
163
163
|
# * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by
|
164
|
-
# non-text columns
|
164
|
+
# non-text columns. The default behavior respects the default database collation.
|
165
165
|
# * <tt>:allow_nil</tt> - If set to +true+, skips this validation if the
|
166
166
|
# attribute is +nil+ (default is +false+).
|
167
167
|
# * <tt>:allow_blank</tt> - If set to +true+, skips this validation if the
|
168
168
|
# attribute is blank (default is +false+).
|
169
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
169
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
170
170
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
171
171
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
172
172
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
173
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
173
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to
|
174
174
|
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
175
175
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
176
|
-
# method, proc or string should return or evaluate to a +true+ or +false+
|
176
|
+
# method, proc, or string should return or evaluate to a +true+ or +false+
|
177
177
|
# value.
|
178
178
|
#
|
179
179
|
# === Concurrency and integrity
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative "gem_version"
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
|
-
# Returns the version of
|
6
|
+
# Returns the currently loaded version of Active Record as a <tt>Gem::Version</tt>.
|
7
7
|
def self.version
|
8
8
|
gem_version
|
9
9
|
end
|