Sha256: 001125a81e0dadf342a261427387d3f19e3c4f3f10ae1332d4f4bc396931353e

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# Generates the class, fixtures, and migration for a model in a plugin's test application
class PluginTestModelGenerator < PluginAWeek::PluginTestHelper::Generator
  default_options :skip_migration => false
  
  def manifest
    record do |m|
      # Check for class naming collisions.
      m.class_collisions class_path, class_name
      
      # Model and fixture directories.
      m.directory File.join(plugin_app_root, 'app/models', class_path)
      m.directory File.join(plugin_app_root, 'test/fixtures', class_path)
      
      # Model class and fixtures.
      m.template 'model.rb',      File.join(plugin_app_root, 'app/models', class_path, "#{file_name}.rb")
      m.template 'fixtures.yml',  File.join(plugin_app_root, 'test/fixtures', class_path, "#{table_name}.yml")
      
      unless options[:skip_migration]
        m.migration_template 'migration.rb', "#{plugin_app_root}/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} generate your_plugin ModelName [field:type, field:type]"
    end
    
    def add_options!(opt)
      opt.separator ''
      opt.separator 'Options:'
      opt.on("--skip-migration", 
             "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plugin_test_helper-0.0.1 generators/plugin_test_model/plugin_test_model_generator.rb
plugin_test_helper-0.0.2 generators/plugin_test_model/plugin_test_model_generator.rb