ubermajestix / grep_routes

Greppin in ur routes
3 stars 0 forks source link

Devise compatibility: undefined method `devise_for' #2

Open ruckus opened 12 years ago

ruckus commented 12 years ago

I am using Devise for authentication and my routes.rb has a line:

devise_for :users, :controllers => { :sessions => "sessions" }

When I invoke grep_routes I receive the following error:

/Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/grep_routes-0.0.5/lib/grep_routes.rb:94:in `eval': undefined method `devise_for' for #<ActionDispatch::Routing::Mapper:0x007f9dcd0e9c60> (NoMethodError)
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `instance_exec'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `eval_block'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:235:in `draw'
    from (eval):1:in `eval_routes'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/grep_routes-0.0.5/lib/grep_routes.rb:94:in `eval'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/grep_routes-0.0.5/lib/grep_routes.rb:94:in `eval_routes'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/gems/grep_routes-0.0.5/bin/grep_routes:9:in `<top (required)>'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/bin/grep_routes:19:in `load'
    from /Users/codyc/.rvm/gems/ruby-1.9.2-p290-patched@vinorails31/bin/grep_routes:19:in `<main>'
ubermajestix commented 12 years ago

Hmmm this might be a hard one to solve.

grep_routes intentionally doesn't load Rails, or any gems. It mocks out objects it finds in your routes file enough so that ActionDispatch's routing can parse the routes. Because I avoid loading Rails we get a massive speed increase.

I'm thinking I may have to attempt to require devise, if needed, so thedevise_for returns something ActionDispatch can work with when routes.rb is eval'd.

Thanks for the feedback!

ruckus commented 12 years ago

Yeah I figured it was due to grep_routes not loading Rails / gems, which is fine.

A plausible workaround would be to document this trade-off and then just rescue from it and continue along...?