blob: 42ff48c75cdf99b90cb4207eda6e16c7ee454f36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
require 'generators/active_record'
module ActiveRecord
module Generators
class ModelGenerator < Base
argument :attributes, :type => :hash, :default => {}, :banner => "field:type field:type"
check_class_collision
conditional_class_options :migration, :timestamps
class_option :parent, :type => :string,
:desc => "The parent class for the generated model"
def create_model_file
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
end
def create_migration_file
if options[:migration] && options[:parent].nil?
file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
migration_template "migration.rb", "db/migrate/#{file_name}.rb"
end
end
hook_for :test_framework
protected
def parent_class_name
options[:parent] || "ActiveRecord::Base"
end
end
end
end
|