activesupport 6.1.3.1 → 7.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +151 -485
  3. data/MIT-LICENSE +1 -1
  4. data/lib/active_support/actionable_error.rb +1 -1
  5. data/lib/active_support/array_inquirer.rb +0 -2
  6. data/lib/active_support/benchmarkable.rb +2 -2
  7. data/lib/active_support/cache/file_store.rb +16 -10
  8. data/lib/active_support/cache/mem_cache_store.rb +119 -28
  9. data/lib/active_support/cache/memory_store.rb +21 -13
  10. data/lib/active_support/cache/null_store.rb +10 -2
  11. data/lib/active_support/cache/redis_cache_store.rb +39 -59
  12. data/lib/active_support/cache/strategy/local_cache.rb +29 -49
  13. data/lib/active_support/cache.rb +196 -46
  14. data/lib/active_support/callbacks.rb +35 -31
  15. data/lib/active_support/concern.rb +5 -5
  16. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +2 -4
  17. data/lib/active_support/concurrency/share_lock.rb +2 -2
  18. data/lib/active_support/configurable.rb +6 -3
  19. data/lib/active_support/configuration_file.rb +7 -2
  20. data/lib/active_support/core_ext/array/access.rb +1 -5
  21. data/lib/active_support/core_ext/array/conversions.rb +6 -6
  22. data/lib/active_support/core_ext/array/grouping.rb +6 -6
  23. data/lib/active_support/core_ext/big_decimal/conversions.rb +1 -1
  24. data/lib/active_support/core_ext/date/blank.rb +1 -1
  25. data/lib/active_support/core_ext/date/calculations.rb +2 -2
  26. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  27. data/lib/active_support/core_ext/digest/uuid.rb +13 -12
  28. data/lib/active_support/core_ext/enumerable.rb +64 -12
  29. data/lib/active_support/core_ext/file/atomic.rb +1 -1
  30. data/lib/active_support/core_ext/hash/keys.rb +1 -1
  31. data/lib/active_support/core_ext/kernel/reporting.rb +4 -4
  32. data/lib/active_support/core_ext/module/delegation.rb +2 -8
  33. data/lib/active_support/core_ext/name_error.rb +2 -8
  34. data/lib/active_support/core_ext/numeric/conversions.rb +2 -2
  35. data/lib/active_support/core_ext/object/blank.rb +2 -2
  36. data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
  37. data/lib/active_support/core_ext/object/duplicable.rb +11 -0
  38. data/lib/active_support/core_ext/object/json.rb +29 -24
  39. data/lib/active_support/core_ext/object/to_query.rb +2 -2
  40. data/lib/active_support/core_ext/object/try.rb +20 -20
  41. data/lib/active_support/core_ext/range/compare_range.rb +0 -25
  42. data/lib/active_support/core_ext/range/each.rb +1 -1
  43. data/lib/active_support/core_ext/range/include_time_with_zone.rb +1 -1
  44. data/lib/active_support/core_ext/string/filters.rb +1 -1
  45. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  46. data/lib/active_support/core_ext/string/output_safety.rb +60 -36
  47. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +0 -8
  48. data/lib/active_support/core_ext/time/calculations.rb +5 -9
  49. data/lib/active_support/core_ext/time/zones.rb +2 -17
  50. data/lib/active_support/core_ext/uri.rb +1 -15
  51. data/lib/active_support/current_attributes.rb +18 -1
  52. data/lib/active_support/dependencies/interlock.rb +10 -18
  53. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  54. data/lib/active_support/dependencies.rb +58 -788
  55. data/lib/active_support/deprecation/behaviors.rb +4 -1
  56. data/lib/active_support/deprecation/method_wrappers.rb +3 -3
  57. data/lib/active_support/deprecation/proxy_wrappers.rb +1 -1
  58. data/lib/active_support/deprecation.rb +1 -1
  59. data/lib/active_support/descendants_tracker.rb +12 -9
  60. data/lib/active_support/digest.rb +5 -3
  61. data/lib/active_support/duration/iso8601_parser.rb +3 -3
  62. data/lib/active_support/duration/iso8601_serializer.rb +9 -1
  63. data/lib/active_support/duration.rb +77 -48
  64. data/lib/active_support/encrypted_configuration.rb +11 -1
  65. data/lib/active_support/encrypted_file.rb +1 -1
  66. data/lib/active_support/environment_inquirer.rb +1 -1
  67. data/lib/active_support/evented_file_update_checker.rb +1 -1
  68. data/lib/active_support/fork_tracker.rb +2 -2
  69. data/lib/active_support/gem_version.rb +4 -4
  70. data/lib/active_support/hash_with_indifferent_access.rb +8 -1
  71. data/lib/active_support/i18n.rb +1 -0
  72. data/lib/active_support/inflector/inflections.rb +11 -4
  73. data/lib/active_support/inflector/methods.rb +23 -47
  74. data/lib/active_support/json/encoding.rb +3 -3
  75. data/lib/active_support/key_generator.rb +18 -1
  76. data/lib/active_support/locale/en.yml +2 -2
  77. data/lib/active_support/log_subscriber.rb +13 -3
  78. data/lib/active_support/logger_thread_safe_level.rb +5 -13
  79. data/lib/active_support/message_encryptor.rb +3 -3
  80. data/lib/active_support/message_verifier.rb +4 -4
  81. data/lib/active_support/messages/metadata.rb +2 -2
  82. data/lib/active_support/multibyte/chars.rb +10 -11
  83. data/lib/active_support/multibyte/unicode.rb +2 -2
  84. data/lib/active_support/multibyte.rb +1 -1
  85. data/lib/active_support/notifications/fanout.rb +31 -11
  86. data/lib/active_support/notifications/instrumenter.rb +17 -0
  87. data/lib/active_support/notifications.rb +10 -0
  88. data/lib/active_support/number_helper/number_converter.rb +1 -3
  89. data/lib/active_support/number_helper/number_to_currency_converter.rb +11 -6
  90. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -1
  91. data/lib/active_support/number_helper/number_to_human_size_converter.rb +1 -1
  92. data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -1
  93. data/lib/active_support/number_helper/number_to_rounded_converter.rb +10 -6
  94. data/lib/active_support/number_helper/rounding_helper.rb +2 -6
  95. data/lib/active_support/number_helper.rb +0 -2
  96. data/lib/active_support/option_merger.rb +4 -16
  97. data/lib/active_support/ordered_hash.rb +1 -1
  98. data/lib/active_support/parameter_filter.rb +5 -0
  99. data/lib/active_support/per_thread_registry.rb +1 -0
  100. data/lib/active_support/railtie.rb +34 -11
  101. data/lib/active_support/rescuable.rb +2 -2
  102. data/lib/active_support/secure_compare_rotator.rb +1 -1
  103. data/lib/active_support/security_utils.rb +1 -1
  104. data/lib/active_support/string_inquirer.rb +0 -2
  105. data/lib/active_support/subscriber.rb +5 -0
  106. data/lib/active_support/tagged_logging.rb +1 -1
  107. data/lib/active_support/test_case.rb +9 -21
  108. data/lib/active_support/testing/assertions.rb +35 -5
  109. data/lib/active_support/testing/deprecation.rb +1 -1
  110. data/lib/active_support/testing/isolation.rb +1 -1
  111. data/lib/active_support/testing/method_call_assertions.rb +5 -5
  112. data/lib/active_support/testing/parallelization/server.rb +4 -0
  113. data/lib/active_support/testing/parallelization/worker.rb +3 -0
  114. data/lib/active_support/testing/parallelization.rb +4 -0
  115. data/lib/active_support/testing/parallelize_executor.rb +76 -0
  116. data/lib/active_support/testing/stream.rb +3 -5
  117. data/lib/active_support/testing/tagged_logging.rb +1 -1
  118. data/lib/active_support/testing/time_helpers.rb +13 -2
  119. data/lib/active_support/time_with_zone.rb +19 -6
  120. data/lib/active_support/values/time_zone.rb +25 -9
  121. data/lib/active_support/xml_mini/jdom.rb +1 -1
  122. data/lib/active_support/xml_mini/libxml.rb +5 -5
  123. data/lib/active_support/xml_mini/libxmlsax.rb +1 -1
  124. data/lib/active_support/xml_mini/nokogiri.rb +4 -4
  125. data/lib/active_support/xml_mini/nokogirisax.rb +1 -1
  126. data/lib/active_support/xml_mini/rexml.rb +1 -1
  127. data/lib/active_support/xml_mini.rb +2 -1
  128. data/lib/active_support.rb +14 -1
  129. metadata +11 -25
  130. data/lib/active_support/core_ext/marshal.rb +0 -26
  131. data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
@@ -5,6 +5,7 @@ require "active_support/descendants_tracker"
5
5
  require "active_support/core_ext/array/extract_options"
6
6
  require "active_support/core_ext/class/attribute"
7
7
  require "active_support/core_ext/string/filters"
8
+ require "active_support/core_ext/object/blank"
8
9
  require "thread"
9
10
 
10
11
  module ActiveSupport
@@ -276,7 +277,7 @@ module ActiveSupport
276
277
  end
277
278
  end
278
279
 
279
- class Callback #:nodoc:#
280
+ class Callback # :nodoc:#
280
281
  def self.build(chain, filter, kind, options)
281
282
  if filter.is_a?(String)
282
283
  raise ArgumentError, <<-MSG.squish
@@ -289,21 +290,17 @@ module ActiveSupport
289
290
  end
290
291
 
291
292
  attr_accessor :kind, :name
292
- attr_reader :chain_config
293
+ attr_reader :chain_config, :filter
293
294
 
294
295
  def initialize(name, filter, kind, options, chain_config)
295
296
  @chain_config = chain_config
296
297
  @name = name
297
298
  @kind = kind
298
299
  @filter = filter
299
- @key = compute_identifier filter
300
300
  @if = check_conditionals(options[:if])
301
301
  @unless = check_conditionals(options[:unless])
302
302
  end
303
303
 
304
- def filter; @key; end
305
- def raw_filter; @filter; end
306
-
307
304
  def merge_conditional_options(chain, if_option:, unless_option:)
308
305
  options = {
309
306
  if: @if.dup,
@@ -356,7 +353,7 @@ module ActiveSupport
356
353
  return EMPTY_ARRAY if conditionals.blank?
357
354
 
358
355
  conditionals = Array(conditionals)
359
- if conditionals.any? { |c| c.is_a?(String) }
356
+ if conditionals.any?(String)
360
357
  raise ArgumentError, <<-MSG.squish
361
358
  Passing string to be evaluated in :if and :unless conditional
362
359
  options is not supported. Pass a symbol for an instance method,
@@ -367,15 +364,6 @@ module ActiveSupport
367
364
  conditionals.freeze
368
365
  end
369
366
 
370
- def compute_identifier(filter)
371
- case filter
372
- when ::Proc
373
- filter.object_id
374
- else
375
- filter
376
- end
377
- end
378
-
379
367
  def conditions_lambdas
380
368
  @if.map { |c| CallTemplate.build(c, self).make_lambda } +
381
369
  @unless.map { |c| CallTemplate.build(c, self).inverted_lambda }
@@ -517,7 +505,7 @@ module ActiveSupport
517
505
  end
518
506
  end
519
507
 
520
- class CallbackChain #:nodoc:#
508
+ class CallbackChain # :nodoc:#
521
509
  include Enumerable
522
510
 
523
511
  attr_reader :name, :config
@@ -619,7 +607,7 @@ module ActiveSupport
619
607
 
620
608
  # This is used internally to append, prepend and skip callbacks to the
621
609
  # CallbackChain.
622
- def __update_callbacks(name) #:nodoc:
610
+ def __update_callbacks(name) # :nodoc:
623
611
  ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse_each do |target|
624
612
  chain = target.get_callbacks name
625
613
  yield target, chain.dup
@@ -688,10 +676,32 @@ module ActiveSupport
688
676
  # <tt>:unless</tt> options may be passed in order to control when the
689
677
  # callback is skipped.
690
678
  #
691
- # class Writer < Person
692
- # skip_callback :validate, :before, :check_membership, if: -> { age > 18 }
679
+ # class Writer < PersonRecord
680
+ # attr_accessor :age
681
+ # skip_callback :save, :before, :saving_message, if: -> { age > 18 }
693
682
  # end
694
683
  #
684
+ # When if option returns true, callback is skipped.
685
+ #
686
+ # writer = Writer.new
687
+ # writer.age = 20
688
+ # writer.save
689
+ #
690
+ # Output:
691
+ # - save
692
+ # saved
693
+ #
694
+ # When if option returns false, callback is NOT skipped.
695
+ #
696
+ # young_writer = Writer.new
697
+ # young_writer.age = 17
698
+ # young_writer.save
699
+ #
700
+ # Output:
701
+ # saving...
702
+ # - save
703
+ # saved
704
+ #
695
705
  # An <tt>ArgumentError</tt> will be raised if the callback has not
696
706
  # already been set (unless the <tt>:raise</tt> option is set to <tt>false</tt>).
697
707
  def skip_callback(name, *filter_list, &block)
@@ -844,18 +854,12 @@ module ActiveSupport
844
854
  __callbacks[name.to_sym]
845
855
  end
846
856
 
847
- if Module.instance_method(:method_defined?).arity == 1 # Ruby 2.5 and older
848
- def set_callbacks(name, callbacks) # :nodoc:
849
- self.__callbacks = __callbacks.merge(name.to_sym => callbacks)
850
- end
851
- else # Ruby 2.6 and newer
852
- def set_callbacks(name, callbacks) # :nodoc:
853
- unless singleton_class.method_defined?(:__callbacks, false)
854
- self.__callbacks = __callbacks.dup
855
- end
856
- self.__callbacks[name.to_sym] = callbacks
857
- self.__callbacks
857
+ def set_callbacks(name, callbacks) # :nodoc:
858
+ unless singleton_class.method_defined?(:__callbacks, false)
859
+ self.__callbacks = __callbacks.dup
858
860
  end
861
+ self.__callbacks[name.to_sym] = callbacks
862
+ self.__callbacks
859
863
  end
860
864
  end
861
865
  end
@@ -108,23 +108,23 @@ module ActiveSupport
108
108
  #
109
109
  # <tt>prepend</tt> is also used for any dependencies.
110
110
  module Concern
111
- class MultipleIncludedBlocks < StandardError #:nodoc:
111
+ class MultipleIncludedBlocks < StandardError # :nodoc:
112
112
  def initialize
113
113
  super "Cannot define multiple 'included' blocks for a Concern"
114
114
  end
115
115
  end
116
116
 
117
- class MultiplePrependBlocks < StandardError #:nodoc:
117
+ class MultiplePrependBlocks < StandardError # :nodoc:
118
118
  def initialize
119
119
  super "Cannot define multiple 'prepended' blocks for a Concern"
120
120
  end
121
121
  end
122
122
 
123
- def self.extended(base) #:nodoc:
123
+ def self.extended(base) # :nodoc:
124
124
  base.instance_variable_set(:@_dependencies, [])
125
125
  end
126
126
 
127
- def append_features(base) #:nodoc:
127
+ def append_features(base) # :nodoc:
128
128
  if base.instance_variable_defined?(:@_dependencies)
129
129
  base.instance_variable_get(:@_dependencies) << self
130
130
  false
@@ -137,7 +137,7 @@ module ActiveSupport
137
137
  end
138
138
  end
139
139
 
140
- def prepend_features(base) #:nodoc:
140
+ def prepend_features(base) # :nodoc:
141
141
  if base.instance_variable_defined?(:@_dependencies)
142
142
  base.instance_variable_get(:@_dependencies).unshift self
143
143
  false
@@ -17,14 +17,12 @@ module ActiveSupport
17
17
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
18
18
  end
19
19
 
20
- def synchronize
20
+ def synchronize(&block)
21
21
  Thread.handle_interrupt(EXCEPTION_NEVER) do
22
22
  mon_enter
23
23
 
24
24
  begin
25
- Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
26
- yield
27
- end
25
+ Thread.handle_interrupt(EXCEPTION_IMMEDIATE, &block)
28
26
  ensure
29
27
  mon_exit
30
28
  end
@@ -215,9 +215,9 @@ module ActiveSupport
215
215
  @waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
216
216
  end
217
217
 
218
- def wait_for(method)
218
+ def wait_for(method, &block)
219
219
  @sleeping[Thread.current] = method
220
- @cv.wait_while { yield }
220
+ @cv.wait_while(&block)
221
221
  ensure
222
222
  @sleeping.delete Thread.current
223
223
  end
@@ -94,17 +94,19 @@ module ActiveSupport
94
94
  # User.new.allowed_access = true # => NoMethodError
95
95
  # User.new.allowed_access # => NoMethodError
96
96
  #
97
- # Also you can pass a block to set up the attribute with a default value.
97
+ # Also you can pass <tt>default</tt> or a block to set up the attribute with a default value.
98
98
  #
99
99
  # class User
100
100
  # include ActiveSupport::Configurable
101
+ # config_accessor :allowed_access, default: false
101
102
  # config_accessor :hair_colors do
102
103
  # [:brown, :black, :blonde, :red]
103
104
  # end
104
105
  # end
105
106
  #
107
+ # User.allowed_access # => false
106
108
  # User.hair_colors # => [:brown, :black, :blonde, :red]
107
- def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true) # :doc:
109
+ def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil) # :doc:
108
110
  names.each do |name|
109
111
  raise NameError.new("invalid config attribute name") unless /\A[_A-Za-z]\w*\z/.match?(name)
110
112
 
@@ -118,7 +120,8 @@ module ActiveSupport
118
120
  class_eval reader, __FILE__, reader_line if instance_reader
119
121
  class_eval writer, __FILE__, writer_line if instance_writer
120
122
  end
121
- send("#{name}=", yield) if block_given?
123
+
124
+ send("#{name}=", block_given? ? yield : default)
122
125
  end
123
126
  end
124
127
  private :config_accessor
@@ -19,7 +19,12 @@ module ActiveSupport
19
19
  end
20
20
 
21
21
  def parse(context: nil, **options)
22
- YAML.load(render(context), **options) || {}
22
+ source = render(context)
23
+ if YAML.respond_to?(:unsafe_load)
24
+ YAML.unsafe_load(source, **options) || {}
25
+ else
26
+ YAML.load(source, **options) || {}
27
+ end
23
28
  rescue Psych::SyntaxError => error
24
29
  raise "YAML syntax error occurred while parsing #{@content_path}. " \
25
30
  "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
@@ -33,7 +38,7 @@ module ActiveSupport
33
38
 
34
39
  File.read(content_path).tap do |content|
35
40
  if content.include?("\u00A0")
36
- warn "File contains invisible non-breaking spaces, you may want to remove those"
41
+ warn "#{content_path} contains invisible non-breaking spaces, you may want to remove those"
37
42
  end
38
43
  end
39
44
  end
@@ -47,11 +47,7 @@ class Array
47
47
  def excluding(*elements)
48
48
  self - elements.flatten(1)
49
49
  end
50
-
51
- # Alias for #excluding.
52
- def without(*elements)
53
- excluding(*elements)
54
- end
50
+ alias :without :excluding
55
51
 
56
52
  # Equal to <tt>self[1]</tt>.
57
53
  #
@@ -16,12 +16,12 @@ class Array
16
16
  #
17
17
  # ==== Options
18
18
  #
19
- # * <tt>:words_connector</tt> - The sign or word used to join the elements
20
- # in arrays with two or more elements (default: ", ").
21
- # * <tt>:two_words_connector</tt> - The sign or word used to join the elements
22
- # in arrays with two elements (default: " and ").
19
+ # * <tt>:words_connector</tt> - The sign or word used to join all but the last
20
+ # element in arrays with three or more elements (default: ", ").
23
21
  # * <tt>:last_word_connector</tt> - The sign or word used to join the last element
24
22
  # in arrays with three or more elements (default: ", and ").
23
+ # * <tt>:two_words_connector</tt> - The sign or word used to join the elements
24
+ # in arrays with two elements (default: " and ").
25
25
  # * <tt>:locale</tt> - If +i18n+ is available, you can set a locale and use
26
26
  # the connector options defined on the 'support.array' namespace in the
27
27
  # corresponding dictionary file.
@@ -66,7 +66,7 @@ class Array
66
66
  two_words_connector: " and ",
67
67
  last_word_connector: ", and "
68
68
  }
69
- if defined?(I18n)
69
+ if options[:locale] != false && defined?(I18n)
70
70
  i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {})
71
71
  default_connectors.merge!(i18n_connectors)
72
72
  end
@@ -187,7 +187,7 @@ class Array
187
187
  options[:indent] ||= 2
188
188
  options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
189
189
  options[:root] ||= \
190
- if first.class != Hash && all? { |e| e.is_a?(first.class) }
190
+ if first.class != Hash && all?(first.class)
191
191
  underscored = ActiveSupport::Inflector.underscore(first.class.name)
192
192
  ActiveSupport::Inflector.pluralize(underscored).tr("/", "_")
193
193
  else
@@ -19,7 +19,7 @@ class Array
19
19
  # ["1", "2"]
20
20
  # ["3", "4"]
21
21
  # ["5"]
22
- def in_groups_of(number, fill_with = nil)
22
+ def in_groups_of(number, fill_with = nil, &block)
23
23
  if number.to_i <= 0
24
24
  raise ArgumentError,
25
25
  "Group size must be a positive integer, was #{number.inspect}"
@@ -36,7 +36,7 @@ class Array
36
36
  end
37
37
 
38
38
  if block_given?
39
- collection.each_slice(number) { |slice| yield(slice) }
39
+ collection.each_slice(number, &block)
40
40
  else
41
41
  collection.each_slice(number).to_a
42
42
  end
@@ -59,7 +59,7 @@ class Array
59
59
  # ["1", "2", "3"]
60
60
  # ["4", "5"]
61
61
  # ["6", "7"]
62
- def in_groups(number, fill_with = nil)
62
+ def in_groups(number, fill_with = nil, &block)
63
63
  # size.div number gives minor group size;
64
64
  # size % number gives how many objects need extra accommodation;
65
65
  # each group hold either division or division + 1 items.
@@ -79,7 +79,7 @@ class Array
79
79
  end
80
80
 
81
81
  if block_given?
82
- groups.each { |g| yield(g) }
82
+ groups.each(&block)
83
83
  else
84
84
  groups
85
85
  end
@@ -90,11 +90,11 @@ class Array
90
90
  #
91
91
  # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
92
92
  # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
93
- def split(value = nil)
93
+ def split(value = nil, &block)
94
94
  arr = dup
95
95
  result = []
96
96
  if block_given?
97
- while (idx = arr.index { |i| yield i })
97
+ while (idx = arr.index(&block))
98
98
  result << arr.shift(idx)
99
99
  arr.shift
100
100
  end
@@ -4,7 +4,7 @@ require "bigdecimal"
4
4
  require "bigdecimal/util"
5
5
 
6
6
  module ActiveSupport
7
- module BigDecimalWithDefaultFormat #:nodoc:
7
+ module BigDecimalWithDefaultFormat # :nodoc:
8
8
  def to_s(format = "F")
9
9
  super(format)
10
10
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "date"
4
4
 
5
- class Date #:nodoc:
5
+ class Date # :nodoc:
6
6
  # No Date is blank:
7
7
  #
8
8
  # Date.today.blank? # => false
@@ -87,7 +87,7 @@ class Date
87
87
  end
88
88
  alias :at_end_of_day :end_of_day
89
89
 
90
- def plus_with_duration(other) #:nodoc:
90
+ def plus_with_duration(other) # :nodoc:
91
91
  if ActiveSupport::Duration === other
92
92
  other.since(self)
93
93
  else
@@ -97,7 +97,7 @@ class Date
97
97
  alias_method :plus_without_duration, :+
98
98
  alias_method :+, :plus_with_duration
99
99
 
100
- def minus_with_duration(other) #:nodoc:
100
+ def minus_with_duration(other) # :nodoc:
101
101
  if ActiveSupport::Duration === other
102
102
  plus_with_duration(-other)
103
103
  else
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "date"
4
4
 
5
- class DateTime #:nodoc:
5
+ class DateTime # :nodoc:
6
6
  # No DateTime is ever blank:
7
7
  #
8
8
  # DateTime.now.blank? # => false
@@ -1,27 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "securerandom"
4
+ require "openssl"
4
5
 
5
6
  module Digest
6
7
  module UUID
7
- DNS_NAMESPACE = "k\xA7\xB8\x10\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" #:nodoc:
8
- URL_NAMESPACE = "k\xA7\xB8\x11\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" #:nodoc:
9
- OID_NAMESPACE = "k\xA7\xB8\x12\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" #:nodoc:
10
- X500_NAMESPACE = "k\xA7\xB8\x14\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" #:nodoc:
8
+ DNS_NAMESPACE = "k\xA7\xB8\x10\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
9
+ URL_NAMESPACE = "k\xA7\xB8\x11\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
10
+ OID_NAMESPACE = "k\xA7\xB8\x12\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
11
+ X500_NAMESPACE = "k\xA7\xB8\x14\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
11
12
 
12
13
  # Generates a v5 non-random UUID (Universally Unique IDentifier).
13
14
  #
14
- # Using Digest::MD5 generates version 3 UUIDs; Digest::SHA1 generates version 5 UUIDs.
15
+ # Using OpenSSL::Digest::MD5 generates version 3 UUIDs; OpenSSL::Digest::SHA1 generates version 5 UUIDs.
15
16
  # uuid_from_hash always generates the same UUID for a given name and namespace combination.
16
17
  #
17
18
  # See RFC 4122 for details of UUID at: https://www.ietf.org/rfc/rfc4122.txt
18
19
  def self.uuid_from_hash(hash_class, uuid_namespace, name)
19
- if hash_class == Digest::MD5
20
+ if hash_class == Digest::MD5 || hash_class == OpenSSL::Digest::MD5
20
21
  version = 3
21
- elsif hash_class == Digest::SHA1
22
+ elsif hash_class == Digest::SHA1 || hash_class == OpenSSL::Digest::SHA1
22
23
  version = 5
23
24
  else
24
- raise ArgumentError, "Expected Digest::SHA1 or Digest::MD5, got #{hash_class.name}."
25
+ raise ArgumentError, "Expected OpenSSL::Digest::SHA1 or OpenSSL::Digest::MD5, got #{hash_class.name}."
25
26
  end
26
27
 
27
28
  hash = hash_class.new
@@ -35,14 +36,14 @@ module Digest
35
36
  "%08x-%04x-%04x-%04x-%04x%08x" % ary
36
37
  end
37
38
 
38
- # Convenience method for uuid_from_hash using Digest::MD5.
39
+ # Convenience method for uuid_from_hash using OpenSSL::Digest::MD5.
39
40
  def self.uuid_v3(uuid_namespace, name)
40
- uuid_from_hash(Digest::MD5, uuid_namespace, name)
41
+ uuid_from_hash(OpenSSL::Digest::MD5, uuid_namespace, name)
41
42
  end
42
43
 
43
- # Convenience method for uuid_from_hash using Digest::SHA1.
44
+ # Convenience method for uuid_from_hash using OpenSSL::Digest::SHA1.
44
45
  def self.uuid_v5(uuid_namespace, name)
45
- uuid_from_hash(Digest::SHA1, uuid_namespace, name)
46
+ uuid_from_hash(OpenSSL::Digest::SHA1, uuid_namespace, name)
46
47
  end
47
48
 
48
49
  # Convenience method for SecureRandom.uuid.