Digest::Digest is deprecated; use Digest

2019-07-11 04:36发布

I am getting the following error

Digest::Digest is deprecated; use Digest

when i try to boot my rails server. I tried to search my source code for Digest::Digest but i am not using it anywhere. any idea how to solve that?

Only place i am using is

<% digest = OpenSSL::Digest.new('sha1') %>

@alias = Digest::MD5.hexdigest(phone)

1条回答
何必那么认真
2楼-- · 2019-07-11 05:04

It is most likely used by one of the gems your app is dependent on.

install (unless already installed) ack tool and run the following command:

# of course, the path to your gems will be different
ack Digest::Digest /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/

It will show you whether any of the gems use it, and if yes - will show you the source code lines.

But basically there is not much you can do:

  1. Check, whether this gem has a newer version, which solves the deprecation warning
  2. Write a patch to the gem, which solves the warning and use patched verions (not cool idea IMO)
  3. Live with warning until gem maintainers work on that
  4. You can silence the depreciation warnings altogether with ActiveSupport::Deprecation.silenced = true (not cool idea as well IMO). There is also a way to silence specific warning, as @max says in comments):

    silenced = [
      /Digest::Digest is deprecated; use Digest/,
      /some other warning/,
    ]
    
    silenced_expr = Regexp.new(silenced.join('|'))
    
    ActiveSupport::Deprecation.behavior = lambda do |msg, stack|
      unless msg =~ silenced_expr
        ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:stderr].call(msg, stack)
      end
    end
    
  5. Do not use this gem

查看更多
登录 后发表回答