1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/lib/active_support/digest.rb
Eugene Kenny b9e7c676ca Don't include ellipsis in truncated digest output
Using `truncate` to limit the length of the digest has the unwanted side
effect of adding an ellipsis when the input is longer than the limit.

Also:
 - Don't instantiate a new object for every digest
 - Rename the configuration option to `hash_digest_class`
 - Update the CHANGELOG entry to describe how to use the feature
2017-12-17 00:49:02 +00:00

20 lines
486 B
Ruby

# frozen_string_literal: true
module ActiveSupport
class Digest #:nodoc:
class <<self
def hash_digest_class
@hash_digest_class ||= ::Digest::MD5
end
def hash_digest_class=(klass)
raise ArgumentError, "#{klass} is expected to implement hexdigest class method" unless klass.respond_to?(:hexdigest)
@hash_digest_class = klass
end
def hexdigest(arg)
hash_digest_class.hexdigest(arg)[0...32]
end
end
end
end