Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix controller generator for ruby 1.9 hash syntax routes #51

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

tombu commented Aug 23, 2013

As already mentioned in #44 I encountered problems with the new_controller generator when using the new hash syntax (Ruby >= 1.9). I took a look at the generator code and found the problems origin. It´s this regular expression: /api_version.*:module\s*(=>|:)\s*("|')#{module_name_for_route(module_name)}("|')/ in https://github.com/bploetz/versionist/blob/master/lib/generators/versionist/new_controller/new_controller_generator.rb#L15

I added a ? in between the : and module to make the colon optional.

Ruby < 1.9:

api_version(:module => 'v1', :header => 'Accept', :value => 'application/vnd.mycompany.com; version=1') do
  ...
end

=> http://rubular.com/r/yUvIUVf79l

Ruby >= 1.9:

api_version(module: 'v1', header: 'Accept', value: 'application/vnd.mycompany.com; version=1') do
  ...
end

=> http://rubular.com/r/yeXkMTf6Et

Do you want me to add specs for that? If yes, do you have a suggestions to do it without introducing a lot of duplicated code?

Owner

bploetz commented Aug 27, 2013

@tombu #44 was due to an incompatibility with module name cases introduced in the Rails inflector in Rails 4. What specific error are you getting due to the new hash syntax? (And while we're at it, have you had a chance to try the fix for #44 yet? I'd really like to release that fix, but want a second person to verify it fixes the case problem for them in Rails 4).

Let me know what error you're getting due to the hash syntax so I have some context for the PR above. Thanks!

Contributor

tombu commented Aug 27, 2013

When I use the generator like this:
$ rails g versionist:new_controller foos V1

I get the following output:

      create  app/controllers/v1/foos_controller.rb
/Users/Thommy/.rvm/gems/ruby-2.0.0-p0/bundler/gems/versionist-18602b9eabd1/lib/generators/versionist/new_controller/new_controller_generator.rb:19:in `block in new_controller': API version doesn't exist in config/routes.rb. Please run 'rails generate versionist:new_api_version' generator first (RuntimeError)

This error led me to the regular expression I mentioned above.

Owner

bploetz commented Aug 28, 2013

@tombu ah ha, I see the issue now, thanks. This same problem exists in the copy_api_version generator as well. I'll merge your change in and add specs and fix the other generator as well. Stay tuned....

Contributor

tombu commented Aug 28, 2013

Nice, thanks. I haven´t used the copy_api_version generator yet hence I didn´t recognize the issue there. Thanks for your help. I appreciate your work!

Owner

bploetz commented Aug 29, 2013

versionist 1.2.1 has this fix. Thanks again.

@bploetz bploetz closed this Aug 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment