New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console hooks are broken #74

Open
nhocki opened this Issue Jun 3, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@nhocki

nhocki commented Jun 3, 2015

Hi,

I'm trying to add default methods to the console like this:

# config/application.rb
# Source http://opensoul.org/2012/11/08/add-helper-methods-to-your-rails-console/
console do
  require 'console_foo'
  Rails::ConsoleMethods.include(ConsoleFoo)
end

Rails includes Rails::ConsoleMethods into the console::ExtendCommandBundle module, in this case that'd be Pry::ExtendCommandBundle which is an empty module so nothing is happening.

I could get this working by doing TOPLEVEL_BINDING.eval('self').extend ConsoleFoo but that seems a lot like a hack, is there a way we could have ExtendCommandBundle work?

The console block gets called before console.start (Pry.start) so maybe there's something to be done there?

Thanks

@mlangenberg

This comment has been minimized.

Show comment
Hide comment
@mlangenberg

mlangenberg Jul 31, 2015

Just ran into this as well. Can confirm that switching back to IRB mitigates the problem.
When you run include Rails::ConsoleMethods in the console, the methods are available again.

class Application < Rails::Application
    module ConsoleHelpers
      def bar; :bar; end
    end
    console do
      module Rails::ConsoleMethods
        include ConsoleHelpers
        def foo; :foo; end
      end
    end
end
rails c
Loading development environment (Rails 4.1.6)
[1] pry(main)> foo
=> :foo
[2] pry(main)> bar
NameError: undefined local variable or method `bar' for main:Object
from (pry):2:in `__pry__'

Funny right?

mlangenberg commented Jul 31, 2015

Just ran into this as well. Can confirm that switching back to IRB mitigates the problem.
When you run include Rails::ConsoleMethods in the console, the methods are available again.

class Application < Rails::Application
    module ConsoleHelpers
      def bar; :bar; end
    end
    console do
      module Rails::ConsoleMethods
        include ConsoleHelpers
        def foo; :foo; end
      end
    end
end
rails c
Loading development environment (Rails 4.1.6)
[1] pry(main)> foo
=> :foo
[2] pry(main)> bar
NameError: undefined local variable or method `bar' for main:Object
from (pry):2:in `__pry__'

Funny right?

@nhocki

This comment has been minimized.

Show comment
Hide comment
@nhocki

nhocki Aug 1, 2015

@mlangenberg yes. Going back to plain IRB fixes the problem. I actually ended up extending TOPLEVEL_BINDING. I blogged about this here.

nhocki commented Aug 1, 2015

@mlangenberg yes. Going back to plain IRB fixes the problem. I actually ended up extending TOPLEVEL_BINDING. I blogged about this here.

@mlangenberg

This comment has been minimized.

Show comment
Hide comment
@mlangenberg

mlangenberg Aug 4, 2015

Thanks for documenting your workaround @nhocki 👍

mlangenberg commented Aug 4, 2015

Thanks for documenting your workaround @nhocki 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment