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

Extension points for parameters #330

Closed
iNecas opened this issue Feb 11, 2015 · 5 comments
Closed

Extension points for parameters #330

iNecas opened this issue Feb 11, 2015 · 5 comments

Comments

@iNecas
Copy link
Member

iNecas commented Feb 11, 2015

We have a Rails app with highly-plugable architecture, where it's possible to add model attributes to from an external engine. So let's say the host app has something like this (putting the strong params aside):

param :person, Hash do
  param :name, String
end
def create
  User.create(params[:person])
end

I could have something like this in a plugin code:

def_param_group :person_extension, Hash, :extend => apipie_action(PeopleController, :create, :person) do
  param :email, String
end

The :extend keyword would mean that this param group should be included when the body of the person param is being evaluated. Similarly, to extend some param group, one would go:

def_param_group :person_extension, Hash, :extend => apipie_param_group(PeopleController, :person_group, :person) do
  param :email, String
end
@stbenjam
Copy link
Contributor

I guess the biggest thing here is I want to be able to add extensions in the context of the controller to make it easier for plugins doing alias_method_chain. I think both of the examples you showed, the block would be executed inside the Apipie DSL.

In the example I had constructed in Foreman (stbenjam/foreman@ffc9009), I had to call the models individually in each param group (Hostgroup.extended_attributes...) because I couldn't use controller methods like resource_class.

So specifically in the plugin case, I'd like to have it all bundled up in some concern I could just include in the various controllers, that would extend "#{resource_class.to.s.whatever}_group" with resource_class.extended_parameters

I'm not sure if that's useful to anyone but Foreman.

@shlomizadok
Copy link

@iNecas @stbenjam - This issue pops up again ( Foreman #16490) , would love to try and promote it

@ares
Copy link

ares commented Dec 19, 2016

And another one Foreman #17678

@iNecas
Copy link
Member Author

iNecas commented Aug 20, 2017

Due to the way the param groups are implemented, it was not possible/easy to allow extending on that level (as we can't never be sure, if the param group was already included somewhere). However, extending on per action basis should work for most cases. See #554 for the implementation.

@iNecas iNecas closed this as completed Aug 21, 2017
@iNecas
Copy link
Member Author

iNecas commented Aug 21, 2017

Fixed via #554

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

No branches or pull requests

4 participants