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

Extracted endpoint dsl #716

Merged
merged 2 commits into from
Aug 12, 2014
Merged

Conversation

dspaeth-faber
Copy link
Contributor

Additional to #714 I extracted also Endpoint specific DSL.

@dblock
Copy link
Member

dblock commented Aug 12, 2014

Good. This gives us a lot of spec work that will make those tests much more specific.

dblock added a commit that referenced this pull request Aug 12, 2014
@dblock dblock merged commit da01659 into ruby-grape:master Aug 12, 2014
@dspaeth-faber dspaeth-faber deleted the extract_end_point_dsl branch August 12, 2014 14:03
dblock added a commit that referenced this pull request Aug 16, 2014
@dblock
Copy link
Member

dblock commented Aug 16, 2014

Some specs filled out in fac8392 and 3b347a3.

@dspaeth-faber
Copy link
Contributor Author

👍

@dblock
Copy link
Member

dblock commented Aug 24, 2014

Note that this removed Grape::API::Helpers which was documented as a way to add things like shared parameters. I re-added that in 3411432. My two questions are whether we should add other modules automatically to Grape::API::Helpers and whether it should go away in favor of Grape::DSL::Helpers instead?

@dblock
Copy link
Member

dblock commented Aug 24, 2014

@dspaeth-faber pls comment on ^^^^, thanks

@dspaeth-faber
Copy link
Contributor Author

@dblock Sorry, I think I need more coffee :)

I did have a look here v0.8.0
and here.

I couldn't see this

add other modules automatically to Grape::API::Helpers

In the released version you still have to call

helpers MyModule

When you don't extend you'r module with Grape::API::Helpers the only thing missing is the DSL Method params. So I think documentation should be changed to include Grape::DSL::Helpers::BaseHelper. But for backward compatibility I would add

module Grape
  module API
     def self.const_missing(name)
       if name.to_sym == 'Helpers'.to_sym
        warn 'Grape::API::Helpers is deprecated use Grape::DSL::Helpers::BaseHelper instead'
        const_set(name, ::Grape::DSL::Helpers::BaseHelper)
       else
         super
       end
     end
  end
end

Did I delete the spec for this behavior or does none exists?

@dspaeth-faber
Copy link
Contributor Author

When I think a little bit more about it, it makes no sense to define params inside a Helper module.
Helpers are method's on Enpoint-Instance level. Params are methods on API-Class level.
If you want reuseable params then there should be another mechanism.

Maybe:

class MyApi < Grape::API
   define_params 'a name' do
     # define your params
  end


   use_params 'a name'
  get '/' do
  end
end

dspaeth-faber pushed a commit to dspaeth-faber/grape that referenced this pull request Aug 25, 2014
dspaeth-faber pushed a commit to dspaeth-faber/grape that referenced this pull request Aug 25, 2014
@dblock
Copy link
Member

dblock commented Aug 25, 2014

Lets bring the discussion to #735, thanks. I think the spec never existed.

I think that for the end user renaming Grape::API::Helpers -> Grape::DSL::Helpers::BaseHelper is rather annoying. In my commit I just included the latter into the former for backwards compatibility, so we're good for now and can talk about whether/how we want to evolve it.

@dm1try
Copy link
Member

dm1try commented Aug 25, 2014

When I think a little bit more about it, it makes no sense to define params inside a Helper module.
Helpers are method's on Enpoint-Instance level. Params are methods on API-Class level.
If you want reuseable params then there should be another mechanism.
Maybe:
class MyApi < Grape::API
define_params 'a name' do
...

In that case, how should I share reusable params between mounted endpoints?

BTW,

Helpers are method's on Enpoint-Instance level. Params are methods on API-Class level.

Helper module methods are methods on "Enpoint-Instance" level. params is helper method on "API-Class" level. In current implementation helper module can include "Enpoint-Instance" and "API-Class" helpers through single syntax helpers.

@dblock @dspaeth-faber guys, you can destroy this mechanism and use just "raw" ruby modules but I have a question.. Do you use this feature?

@dspaeth-faber
Copy link
Contributor Author

@dm1try PLZ move over to #735 There is example code and demonstrate how it can be done.

Only one brief word, "raw" modules don't work with params and other DSL Methods provided through grape.

But PLZ move over to #735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants