Sha256: 41dbd26d8b2953ba967a955a4c9c4e62aea2eefebc616bd94c77478ffc88ca4e

Contents?: true

Size: 711 Bytes

Versions: 3

Compression:

Stored size: 711 Bytes

Contents

require "rails/generators"

module Statesman
  class MongoidTransitionGenerator < Rails::Generators::Base
    desc "Create a Mongoid-based transition model with the required attributes"

    argument :parent, type: :string, desc: "Your parent model name"
    argument :klass, type: :string, desc: "Your transition model name"

    source_root File.expand_path('../templates', __FILE__)

    def create_model_file
      template("mongoid_transition_model.rb.erb", model_file_name)
    end

    private

    def model_file_name
      "app/models/#{klass.underscore}.rb"
    end

    def collection_name
      klass.underscore.pluralize
    end

    def parent_id
      parent.underscore + "_id"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statesman-0.5.0 lib/generators/statesman/mongoid_transition_generator.rb
statesman-0.4.0 lib/generators/statesman/mongoid_transition_generator.rb
statesman-0.3.0 lib/generators/statesman/mongoid_transition_generator.rb