graphiti-api / graphiti-rails

MIT License
54 stars 28 forks source link

Add namespace option to resource generator for controllers #53

Open dineshpanda opened 4 years ago

dineshpanda commented 4 years ago

Currently, when we generate a resource through generator corresponding controller is also generated. If we have already a controller with similar name, then it prompts us to manually resolve the conflict. However we have skip option to avoid this conflict, but in that case we will lose the generated controller.

So it makes sense to have an option to generate namespaced controller and this PR offers the followings to serve the purpose:

Closes #53

dineshpanda commented 4 years ago

@richmolj Could you please review this PR and let me know if any changes needed.

richmolj commented 4 years ago

@dineshpanda thanks so much for this work and apologies for the delay.

I think accepting a namespace is a fantastic idea others have asked for. I do think if the option is --namespace we should also update the resources, tests, etc. If it's just the controller, maybe something like -c ControllerName instead?

dineshpanda commented 4 years ago

@richmolj It is only to namespace controllers and by default the namespace value within .graphititcfg.yml will be considered as the namespace i.e api/v1

-c sounds good to me. A sample generation as follows:

rails generate graphiti:resource User email name -c

      create  app/controllers/api/v1/users_controller.rb
      insert  config/routes.rb
      create  app/resources/user_resource.rb
      create  spec/resources/user/writes_spec.rb
      create  spec/resources/user/reads_spec.rb
      create  spec/api/v1/users/index_spec.rb
      create  spec/api/v1/users/show_spec.rb
      create  spec/api/v1/users/create_spec.rb
      create  spec/api/v1/users/update_spec.rb
      create  spec/api/v1/users/destroy_spec.rb

Let me know what do you think about this, so that I can make the necessary changes.

I did not see specs for generators, let me know if that is be added.

richmolj commented 4 years ago

I think I'd prefer -c ControllerName instead of relying on the config file. I'm happy to have it fall back to the config file, but accepting the name as an option seems the most straightforward way to document. I'd be good with that.

And yeah no generator specs, would be nice but haven't put in the effort. Thanks for your help ❤️ !