Sha256: ebdf2e7172b8d43d50f97f479e36d8405419e227d6d880fe95f78229e4be0264

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'rubygems'
require 'active_record'

class ModelGenerator < RubiGen::Base
  attr_reader :name,:class_name,:file_name,:class_path,:table_name,:attributes

  def initialize(runtime_args, runtime_options = {})
    super
    usage if args.empty?
    @destination_root = File.expand_path('.')
    @name             = args.shift
		@attributes				= []

		args.map do |x|
			@attributes << {:type => x.split(/:/)[1],:name => x.split(/:/)[0]}
		end

    @file_name  = @name.pluralize.underscore
    @class_name = @name.singularize.classify
    @class_path = File.dirname(@file_name)
		@table_name = file_name.gsub(/\//, '_').pluralize
  end

  def manifest
    record do |m|
      m.directory File.join("test/app_root/app/models",class_path)

      m.template 'model.rb',File.join("test/app_root", 'app/models',"#{file_name}.rb")
      # Migration
      m.migration_template 'migration.rb', "test/app_root/db/migrate", :assigns => {
        :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
      }, :migration_file_name => "create_#{@table_name}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newplugin-0.0.1 generators/model/model_generator.rb