ctran / annotate_models

Annotate Rails classes with schema and routes info
Other
4.41k stars 600 forks source link

Procs are badly annotated #369

Closed pupeno closed 5 years ago

pupeno commented 8 years ago

When you have a route with proc, such as:

match "/users/invitation", via: :all, to: proc { raise ActionController::RoutingError.new('Not Found') }

the route is annotated exposing local paths and with an id that may change:

#           users_invitation        /users/invitation(.:format)                             #<Proc:0x007ffa23247d98@/Users/pupeno/project_x/config/routes.rb:3>

It would be better to just or something like that.

b264 commented 8 years ago

I have seen the same thing. Every run produces a git diff because the number changes.

#   Prefix Verb   URI Pattern            Controller#Action
#                 /__OPAL_SOURCE_MAPS__  #<Opal::SourceMapServer:49235340>

Maybe .class.name should annotate if it's not a string?

JoeWoodward commented 8 years ago

+1 I'm experiencing this issue on every merge from another developer. It's becoming fairly annoying. Does anyone know the offending code so I can have a go at fixing it?

b264 commented 8 years ago

It appears to be coming from Rails and not from annotate. https://github.com/ctran/annotate_models/blob/develop/lib/annotate/annotate_routes.rb#L54

b264 commented 8 years ago

possibly from here ? https://github.com/rails/rails/blob/643cac08a325243cab21d870c68a9c4088c58380/actionpack/lib/action_dispatch/routing/inspector.rb#L8

vlad-shatskyi commented 7 years ago

A workaround:

  invitation_endpoint = proc { raise ActionController::RoutingError.new('Not Found') }.tap do |proc|
    def proc.inspect
      'proc endpoint'
    end
  end

  match "/users/invitation", via: :all, to: invitation_endpoint