eivan/PadrinoEatsGrape

Cannot display padrino routes

jgaldrich opened this issue · 5 comments

Thanks for the great example. I am able to make service requests just fine, but have found that when running: 'padrino rake routes' I receive the following exception:

<Class:0x27148845>: undefined method `named' for #<Grape::Route:0x4c708d30>
          method_missing at org/jruby/RubyBasicObject.java:1652
          method_missing at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/gems/grape-0.2.6/lib/grape/route.rb:14
            named_routes at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/mounter.rb:109
                     map at org/jruby/RubyArray.java:2361
            named_routes at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/mounter.rb:108
         list_app_routes at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:25
                  (root) at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:42
                    each at org/jruby/RubyArray.java:1613
                  (root) at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:41
                    call at org/jruby/RubyProc.java:249
                 execute at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/task.rb:228
                    each at org/jruby/RubyArray.java:1613
                 execute at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/task.rb:223
  invoke_with_call_chain at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/task.rb:166
         mon_synchronize at /Users/jaldrich/.rvm/rubies/jruby-1.7.2/lib/ruby/1.9/monitor.rb:211
  invoke_with_call_chain at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/task.rb:159
                  invoke at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/task.rb:152
             invoke_task at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/application.rb:143
               top_level at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/application.rb:101
                    each at org/jruby/RubyArray.java:1613
               top_level at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/application.rb:101
        run_with_threads at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/application.rb:110
               top_level at /Users/jaldrich/.rvm/gems/jruby-1.7.2@global/gems/rake-10.0.3/lib/rake/application.rb:95
                    init at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake.rb:15
                    rake at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/base.rb:52
                __send__ at org/jruby/RubyBasicObject.java:1665
                    send at org/jruby/RubyKernel.java:2090
                     run at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/gems/thor-0.16.0/lib/thor/task.rb:27
             invoke_task at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/gems/thor-0.16.0/lib/thor/invocation.rb:120
                dispatch at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/gems/thor-0.16.0/lib/thor.rb:275
                   start at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/gems/thor-0.16.0/lib/thor/base.rb:425
                  (root) at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/bin/padrino:9
                    load at org/jruby/RubyKernel.java:1046
                  (root) at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bin/padrino:1
                    eval at org/jruby/RubyKernel.java:1066
                  (root) at /Users/jaldrich/.rvm/gems/jruby-1.7.2@padrino-jruby/bin/ruby_noexec_wrapper:14

Hi!

I haven't tested it with JRuby.
I recommend you Ruby >=1.9.3 or equivalent.

If that's not an option, try and define the method "named" for yourself.
maybe
class Object; def named; "nothing"; end
could do it.

I can reproduce this error with MRI ruby 1.9.3 as well. Here's the trace:

/Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/grape-0.2.6/lib/grape/route.rb:14:in `method_missing': undefined method `named' for version=v1, method=GET, path=/global/:version/accounts(.:format):Grape::Route (NoMethodError)
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/mounter.rb:109:in `block in named_routes'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/mounter.rb:108:in `map'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/mounter.rb:108:in `named_routes'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:25:in `list_app_routes'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:42:in `block (2 levels) in <top (required)>'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:41:in `each'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake_tasks.rb:41:in `block in <top (required)>'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
    from /Users/jaldrich/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/rake.rb:15:in `init'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/lib/padrino-core/cli/base.rb:52:in `rake'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/thor-0.16.0/lib/thor/task.rb:27:in `run'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/thor-0.16.0/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/thor-0.16.0/lib/thor.rb:275:in `dispatch'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/gems/thor-0.16.0/lib/thor/base.rb:425:in `start'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bundler/gems/padrino-framework-3d0c80d55c6d/padrino-core/bin/padrino:9:in `<top (required)>'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bin/padrino:23:in `load'
    from /Users/jaldrich/.rvm/gems/ruby-1.9.3-p194@padrino/bin/padrino:23:in `<main>'

You know, I've made this "hack" based on padrino's App class, by defining some other methods..
see: https://github.com/eivan/PadrinoEatsGrape/blob/master/api/app.rb

Maybe you're using a newer version of Padrino, that requires the method "named"

please try to find out what that method should do, then implement it in this "hack". You can check Padrino's source any time. If you're stuck i can help.

Same issue here on Padrino 0.11.0, Ruby 2.0.0-p0:

rake aborted!
undefined method `name' for #<Grape::Route:0x007fecfd8db1d8>
/usr/local/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/grape-0.4.0/lib/grape/route.rb:14:in `method_missing'
/usr/local/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/padrino-framework-9ea0fa41b417/padrino-core/lib/padrino-core/mounter.rb:109:in `block in named_routes'

Padrino expects route objects to respond to a few HttpRouter::Route methods.
You can monkey patch Grape's Route by adding something like this to your boot.rb#Padrino.before_load block:

class Grape::Route
  def name
    "APIv#{route_version}"
  end
  def request_methods
    Set.new [route_method]
  end
  def original_path
    route_path
  end
end

You will also need to implement the controller method with newer versions of padrino/grape. E.g.:

# config/boot.rb

# ...

Padrino.before_load do
  Padrino.dependency_paths << Padrino.root('api/*.rb')
  class Grape::Route
    def name
      "APIv#{route_version}"
    end
    def request_methods
      Set.new [route_method]
    end
    def original_path
      route_path
    end
    def controller
    end
  end
end