Skip to content
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

Expose source location in API definition #295

Closed
dblock opened this issue Dec 25, 2012 · 2 comments
Closed

Expose source location in API definition #295

dblock opened this issue Dec 25, 2012 · 2 comments

Comments

@dblock
Copy link
Member

dblock commented Dec 25, 2012

It used to be possible to get access to the original API block at runtime via env['api.endpoint'].block, so you could do something like env['api.endpoint'].block.source_location to figure out where the API was actually defined.

Since 3bbb4fe we create an anonymous method, then drop it, losing this information.

For debugging purposes it would be useful to expose block properties at the level of the endpoint.

@dblock
Copy link
Member Author

dblock commented Dec 25, 2012

Currently we can enable this with a monkey patch:

module Grape
  class Endpoint
    alias_method :endpoint_initialize, :initialize
    def initialize(settings, options = {}, &block)
      endpoint_initialize settings, options, &block
      options[:source_location] = block.source_location if block_given?
    end
  end
end

Want to know where the API call was defined?

env['api.endpoint'].options[:source_location]

@dblock
Copy link
Member Author

dblock commented Dec 27, 2012

With e2b12e4 you can just do source.source_location in any API block.

@dblock dblock closed this as completed Dec 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant