aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-04-11 09:27:45 +0100
committerJosé Valim <jose.valim@gmail.com>2010-04-12 10:57:27 +0200
commit788d9238931bb36ed2af78d34c84562dc3a4848c (patch)
treed3ce4f2535226bcbb273b0cc024b60b2d12beea8 /activerecord
parentb9b9f9ee15e2282e9c765d86cb8b6120e2bdb1b9 (diff)
downloadrails-788d9238931bb36ed2af78d34c84562dc3a4848c.tar.gz
rails-788d9238931bb36ed2af78d34c84562dc3a4848c.tar.bz2
rails-788d9238931bb36ed2af78d34c84562dc3a4848c.zip
Generate module file for namespaced models [#4230 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/rails/generators/active_record/model/model_generator.rb5
-rw-r--r--activerecord/lib/rails/generators/active_record/model/templates/module.rb5
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
index 3e72fbeca8..539c2517ee 100644
--- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
@@ -20,6 +20,11 @@ module ActiveRecord
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
end
+ def create_module_file
+ return if class_path.empty?
+ template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb")
+ end
+
hook_for :test_framework
protected
diff --git a/activerecord/lib/rails/generators/active_record/model/templates/module.rb b/activerecord/lib/rails/generators/active_record/model/templates/module.rb
new file mode 100644
index 0000000000..bb4220f038
--- /dev/null
+++ b/activerecord/lib/rails/generators/active_record/model/templates/module.rb
@@ -0,0 +1,5 @@
+module <%= class_path.map(&:camelize).join('::') %>
+ def self.table_name_prefix
+ '<%= class_path.join('_') %>_'
+ end
+end