diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-27 15:41:29 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-27 21:30:00 +0200 |
commit | 7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7 (patch) | |
tree | 2ef794a8dd1454b37e3bff4df4c7e1643eeee050 /railties/lib/generators | |
parent | ff44e5055cd92ee9c49c315cfffa3b0eb4feb844 (diff) | |
download | rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.tar.gz rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.tar.bz2 rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.zip |
Added parent option to model generator.
Diffstat (limited to 'railties/lib/generators')
-rw-r--r-- | railties/lib/generators/active_record/model/model_generator.rb | 14 | ||||
-rw-r--r-- | railties/lib/generators/active_record/model/templates/model.rb | 2 | ||||
-rw-r--r-- | railties/lib/generators/base.rb | 4 |
3 files changed, 9 insertions, 11 deletions
diff --git a/railties/lib/generators/active_record/model/model_generator.rb b/railties/lib/generators/active_record/model/model_generator.rb index 448bf5c37f..45e773fde1 100644 --- a/railties/lib/generators/active_record/model/model_generator.rb +++ b/railties/lib/generators/active_record/model/model_generator.rb @@ -5,16 +5,11 @@ module ActiveRecord check_class_collision - # TODO Add parent support + conditional_class_option :timestamps + conditional_class_option :migration - # TODO Add DEFAULTS support - class_option :skip_timestamps, :type => :boolean, :default => false, - :desc => "Don't add timestamps to the migration file" - - # TODO Make this a invoke_if - # TODO Add DEFAULTS support - class_option :skip_migration, :type => :boolean, :default => false, - :desc => "Don't generate a migration file" + class_option :parent, :type => :string, :default => "ActiveRecord::Base", + :desc => "The parent class for the generated model" def create_model_file template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") @@ -28,6 +23,7 @@ module ActiveRecord # }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" # end end + end end end diff --git a/railties/lib/generators/active_record/model/templates/model.rb b/railties/lib/generators/active_record/model/templates/model.rb index 0656b06dfe..fb337d10e6 100644 --- a/railties/lib/generators/active_record/model/templates/model.rb +++ b/railties/lib/generators/active_record/model/templates/model.rb @@ -1,4 +1,4 @@ -class <%= class_name %> < ActiveRecord::Base +class <%= class_name %> < <%= options[:parent] %> <% attributes.select {|attr| attr.reference? }.each do |attribute| -%> belongs_to :<%= attribute.name %> <% end -%> diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index b9ec9eea62..5dd3b2aa84 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -5,9 +5,11 @@ module Rails DEFAULTS = { :fixture => true, :helper => true, + :migration => true, :orm => 'active_record', :test_framework => 'test_unit', - :template_engine => 'erb' + :template_engine => 'erb', + :timestamps => true } ALIASES = { |