bploetz / versionist

A plugin for versioning Rails based RESTful APIs.
MIT License
971 stars 51 forks source link

new_presenter_generator doesn't work with namespaces #47

Closed softwaregravy closed 11 years ago

softwaregravy commented 11 years ago

I have a version (v20130701 ) set up under an Api namespace.

$ rails g versionist:new_presenter customer_record v20130701 Api
gems/versionist-1.1.0/lib/generators/versionist/new_presenter/new_presenter_generator.rb:12:in `block in new_presenter': API module namespace v20130701 doesn't exist. Please run 'rails generate versionist:new_api_version' generator first (RuntimeError)

So my folder structure for the presenters is app/presenters/api/v20130701.

Running the following will generate the files in the right place:

rails g versionist:new_presenter customer_record api/v2013070

However, they are flawed with classnames:

class api/v20130701::CustomerRecordPresenter < api/v20130701::BasePresenter

vs. the correct output of

class Api::V20130701::CustomerRecordPresenter < Api::V20130701::BasePresenter
bploetz commented 11 years ago

Which version of Rails and which version of Versionist are you seeing this with?

softwaregravy commented 11 years ago

Rails 3.2.12 and versionist 1.1.0

bploetz commented 11 years ago

This works for me:

> rails g versionist:new_presenter customer_record Api::V1
      create  app/presenters/api/v1/customer_record_presenter.rb
      create  test/presenters/api/v1/customer_record_presenter_test.rb

> more app/presenters/api/v1/customer_record_presenter.rb 
class Api::V1::CustomerRecordPresenter < Api::V1::BasePresenter

  def initialize(customer_record)
    @customer_record = customer_record
  end

  def as_json(options={})
    # fill me in...
  end

  def to_xml(options={}, &block)
    xml = options[:builder] ||= Builder::XmlMarkup.new
    # fill me in...
  end
end
bploetz commented 11 years ago

This appears to work for me as noted above. Re-open this if you find this not to be the case.

softwaregravy commented 11 years ago

Looks like I mis-interpreted the docs.

I used

rails generate versionist:new_presenter <name> <module> <namespace>

vs.

rails generate versionist:new_presenter <name> <module namespace>