Skip to content

Commit 33ca392

Browse files
authored
Avoid adding new method to ActiveSupport.
We don't need this delegation and can be setting directly to the right object. Also document the new configuration.
1 parent fbd11ab commit 33ca392

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
# frozen_string_literal: true
22

33
require "active_support/core_ext/digest/uuid"
4-
5-
module ActiveSupport
6-
class << self
7-
delegate :use_rfc4122_namespaced_uuids, :use_rfc4122_namespaced_uuids=, to: :'Digest::UUID'
8-
end
9-
end

activesupport/lib/active_support/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Railtie < Rails::Railtie # :nodoc:
133133
config.after_initialize do
134134
if app.config.active_support.use_rfc4122_namespaced_uuids
135135
require "active_support/core_ext/digest"
136-
ActiveSupport.use_rfc4122_namespaced_uuids = app.config.active_support.use_rfc4122_namespaced_uuids
136+
::Digest::UUID.use_rfc4122_namespaced_uuids = app.config.active_support.use_rfc4122_namespaced_uuids
137137
end
138138
end
139139
end

activesupport/test/core_ext/digest/uuid_test.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
require "active_support/core_ext/digest"
55

66
class DigestUUIDExt < ActiveSupport::TestCase
7-
def with_use_rfc4122_namespaced_uuids_set
8-
old_value = ActiveSupport.use_rfc4122_namespaced_uuids
9-
ActiveSupport.use_rfc4122_namespaced_uuids = true
10-
yield
11-
ensure
12-
ActiveSupport.use_rfc4122_namespaced_uuids = old_value
13-
end
14-
157
def test_constants
168
assert_equal "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "%08x-%04x-%04x-%04x-%04x%08x" % Digest::UUID::DNS_NAMESPACE.unpack("NnnnnN")
179
assert_equal "6ba7b811-9dad-11d1-80b4-00c04fd430c8", "%08x-%04x-%04x-%04x-%04x%08x" % Digest::UUID::URL_NAMESPACE.unpack("NnnnnN")
@@ -184,4 +176,13 @@ def test_invalid_hash_class
184176
Digest::UUID.uuid_from_hash(OpenSSL::Digest::SHA256, Digest::UUID::OID_NAMESPACE, "1.2.3")
185177
end
186178
end
179+
180+
private
181+
def with_use_rfc4122_namespaced_uuids_set
182+
old_value = Digest::UUID.use_rfc4122_namespaced_uuids
183+
Digest::UUID.use_rfc4122_namespaced_uuids = true
184+
yield
185+
ensure
186+
Digest::UUID.use_rfc4122_namespaced_uuids = old_value
187+
end
187188
end

guides/source/configuring.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
17291729
- `config.active_support.cache_format_version`: `7.0`
17301730
- `config.active_support.remove_deprecated_time_with_zone_name`: `true`
17311731
- `config.active_support.executor_around_test_case`: `true`
1732+
- `config.active_support.use_rfc4122_namespaced_uuids`: `true`
17321733
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `false`
17331734
- `config.action_controller.silence_disabled_session_errors`: `false`
17341735
- `config.action_mailer.smtp_timeout`: `5`
@@ -1816,6 +1817,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
18161817
- `config.active_support.key_generator_hash_digest_class`: `OpenSSL::Digest::SHA1`
18171818
- `config.active_support.cache_format_version`: `6.1`
18181819
- `config.active_support.executor_around_test_case`: `false`
1820+
- ``config.active_support.use_rfc4122_namespaced_uuids``: `false`
18191821
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `true`
18201822
- `ActiveSupport.utc_to_local_returns_utc_offset_times`: `false`
18211823
- `config.action_mailer.smtp_timeout`: `nil`

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,10 @@
9797
# Previously this was set in an initializer. It's fine to keep using that initializer if you've customized it.
9898
# To disable parameter wrapping entirely, set this config to `false`.
9999
# Rails.application.config.action_controller.wrap_parameters_by_default = true
100+
101+
# Specifies whether generated namespaced UUIDs follow the RFC 4122 standard for namespace IDs provided as a
102+
# `String` to `Digest::UUID.uuid_v3` or `Digest::UUID.uuid_v5` method calls.
103+
#
104+
# See https://guides.rubyonrails.org/configuring.html#config-active-support-use-rfc4122-namespaced-uuids for
105+
# more information
106+
# Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true

railties/test/application/configuration_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,18 +2422,18 @@ def index
24222422
assert_equal 1234, ActiveSupport.test_parallelization_threshold
24232423
end
24242424

2425-
test "ActiveSupport.use_rfc4122_namespaced_uuids is enabled by default for new apps" do
2425+
test "Digest::UUID.use_rfc4122_namespaced_uuids is enabled by default for new apps" do
24262426
app "development"
24272427

2428-
assert_equal true, ActiveSupport.use_rfc4122_namespaced_uuids
2428+
assert_equal true, Digest::UUID.use_rfc4122_namespaced_uuids
24292429
end
24302430

2431-
test "ActiveSupport.use_rfc4122_namespaced_uuids is disabled by default for upgraded apps" do
2431+
test "Digest::UUID.use_rfc4122_namespaced_uuids is disabled by default for upgraded apps" do
24322432
remove_from_config '.*config\.load_defaults.*\n'
24332433

24342434
app "development"
24352435

2436-
assert_equal false, ActiveSupport.use_rfc4122_namespaced_uuids
2436+
assert_equal false, Digest::UUID.use_rfc4122_namespaced_uuids
24372437
end
24382438

24392439
test "custom serializers should be able to set via config.active_job.custom_serializers in an initializer" do

0 commit comments

Comments
 (0)