bploetz/versionist

new_presenter_generator doesn't work with namespaces

softwaregravy opened this issue · 5 comments

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

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

Rails 3.2.12 and versionist 1.1.0

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

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

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>