Sha256: b8efe822c22e4ccc9760355c20d8f6c4708307f00efb7f9e74a1aa52eeb30125

Contents?: true

Size: 1.73 KB

Versions: 9

Compression:

Stored size: 1.73 KB

Contents

require 'rails_generator/generators/components/model/model_generator'
require File.dirname(__FILE__) + '/../terraforming'

class TerramodelGenerator < ModelGenerator
  include Terraforming

  def manifest

    record do |m|
      m.class_collisions class_path, class_name

      m.directory File.join('app/models', class_path)
      m.directory File.join('spec/models', class_path)
      if exemplar?
        m.directory File.join('spec/exemplars', class_path)
      end
      if factory?
        m.directory File.join('spec/factories')
      end

      m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
      m.template 'model_spec.rb.erb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
      if exemplar?
        m.template 'model_exemplar.rb.erb', File.join('spec/exemplars', class_path, "#{file_name}_exemplar.rb")
      end
      if factory?
        m.template 'model_factory.rb.erb', File.join('spec/factories', "#{full_name}_factory.rb")
      end
      if exist?('spec/fixtures')
        m.template 'model:fixtures.yml',  File.join('spec/fixtures', "#{table_name}.yml")
      end

      unless options[:skip_migration]
        m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
          :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
        }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
      end

    end
  end

  protected

  def banner
    "Usage: #{$0} terramodel ModelName [field:type field:type]"
  end

  def add_options!(opt)
    super
    opt.on("--[no-]exemplar", "Create Object Daddy Exemplar") { |v| options[:exemplar] = v }
    opt.on("--[no-]factory",  "Create Factory Girl Factory")  { |v| options[:factory]  = v }
  end

end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
hashrocket-hashrocket-terraformation-0.0.0 rails_generators/terramodel/terramodel_generator.rb
hashrocket-terraformation-0.0.0 rails_generators/terramodel/terramodel_generator.rb
hashrocket-terraformation-0.1.0 rails_generators/terramodel/terramodel_generator.rb
hashrocket-terraformation-0.1.2 rails_generators/terramodel/terramodel_generator.rb
terraformation-0.2.2 rails_generators/terramodel/terramodel_generator.rb
terraformation-0.2.1 rails_generators/terramodel/terramodel_generator.rb
terraformation-0.2.0 rails_generators/terramodel/terramodel_generator.rb
terraformation-0.1.3 rails_generators/terramodel/terramodel_generator.rb
terraformation-0.1.2 rails_generators/terramodel/terramodel_generator.rb