Search code examples
ruby-on-railsruby-on-rails-3.2sidekiq

Start Rails server with a require statement by passing an argument


Sometimes I use pry and pry-debug to debug my Rails application. This is only a problem if I use additional Ruby processes, like in my case I use Sidekiq.

In order to make the Sidekiq code debugable as well I have to add the following statement

require sidekiq/testing/inline

This is fine, but it's very cumbersome to comment it every time in and out. Is there a way to automate this? I thought maybe it's a good idea to create a sub-class environment for this. Take all the parameters like the :development environment, but add this requirement and then I could start it like so

$ rails server -e debug

Does that make sense? I just don't know how to clone or subclass an environment, create a debug.rb in config/environments, and then?


Solution

  • First solution that comes to my mind is little bit hackish, but at least it should work for you ;).

    require sidekiq/testing/inline if ENV['DEBUG_ENV']
    

    Then just:

    $ DEBUG_ENV=1 rails server
    

    I would go for debug environmenr only if you have more things to change.