blob: 5c6033629f7a149579e247e40d72fb16bf075e4d (
plain) (
tree)
|
|
require 'generators/active_record'
module ActiveRecord
module Generators
class ModelGenerator < Base
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
check_class_collision
class_option :migration, :type => :boolean
class_option :timestamps, :type => :boolean
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
def create_migration_file
if options[:migration] && options[:parent].nil?
klass_name = file_path.gsub(/\//, '_')
klass_name = klass_name.pluralize if ActiveRecord::Base.pluralize_table_names
file_name = "create_#{klass_name}"
migration_template "migration.rb", "db/migrate/#{file_name}.rb"
end
end
def create_model_file
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
end
hook_for :test_framework
protected
def parent_class_name
options[:parent] || "ActiveRecord::Base"
end
end
end
end
|