Loading commander gem in a Rails 4 environment triggers: "DEPRECATION WARNING: RAILS_CACHE is deprecated!" #58

Closed
mattbrictson opened this Issue Aug 5, 2013 · 5 comments

Projects

None yet

2 participants

@mattbrictson

If I do require "commander" inside a Rails 4 app, I get this message:

DEPRECATION WARNING: RAILS_CACHE is deprecated! Use ::Rails.cache instead.

This seems to be a side-effect of how activesupport implements its deprecation mechanism. Commander goes through all global constants and calls respond_to? on them, triggering the deprecation warning for the RAILS_CACHE constant.

I'm not sure if this is a commander or an activesupport issue.

Here's the full trace in IRB:

$ rails c -s
Loading development environment in sandbox (Rails 4.0.0)
Any modifications you make will be rolled back on exit
>> ActiveSupport::Deprecation.debug = true
=> true
>> require 'commander'
DEPRECATION WARNING: RAILS_CACHE is deprecated! Use ::Rails.cache instead. (called from irb_binding at (irb):3)
/Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:330:in `block in <module:AskForClass>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:329:in `select'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:329:in `<module:AskForClass>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:322:in `<module:UI>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:13:in `<module:Commander>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:4:in `<top (required)>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander.rb:27:in `<top (required)>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  (irb):3:in `irb_binding'
@ggilder
Collaborator
ggilder commented Aug 6, 2013

Hmm. It doesn't seem like calling introspection methods like is_a? and respond_to? should trigger the deprecation warning, but maybe it's just applied to all methods.

@mattbrictson

Yes, the deprecation warning seems to be triggered on all methods except inspect. For example, respond_to?:

>> ::RAILS_CACHE.respond_to?(:parse)
DEPRECATION WARNING: RAILS_CACHE is deprecated! Use ::Rails.cache instead. (called from irb_binding at (irb):1)
=> false

Here is the basic implementation from activesupport:

class DeprecationProxy #:nodoc:
  def self.new(*args, &block)
    object = args.first

    return object unless object
    super
  end

  instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ }

  # Don't give a deprecation warning on inspect since test/unit and error
  # logs rely on it for diagnostics.
  def inspect
    target.inspect
  end

  private
    def method_missing(called, *args, &block)
      warn caller, called, args
      target.__send__(called, *args, &block)
    end
end

Should commander work around this, or do you think I should raise this as an issue with activesupport?

@ggilder ggilder added a commit to ggilder/commander that referenced this issue Aug 11, 2013
@ggilder ggilder Avoid triggering ActiveSupport deprecation warning (#58) b475b6e
@ggilder
Collaborator
ggilder commented Aug 11, 2013

@mbrictson could you try this commit and confirm if it fixes the problem? It works for me. b475b6e

@mattbrictson

Yes, that fixes the deprecation warning for me. Thanks!

@ggilder
Collaborator
ggilder commented Aug 11, 2013

Cool, I've just released 4.1.5 with this fix incorporated.

@ggilder ggilder closed this Aug 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment