aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/named_base.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-04 18:13:27 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-04 20:17:32 +0200
commitb277cf28e8a6f5636d0485ab8c04ea0660444440 (patch)
treee7b99a8e16308854a2b1dadbb50f0c69daf418b7 /railties/lib/generators/named_base.rb
parent35925a8995e4b3522e4a4e4e52a3a18c9c1cee52 (diff)
downloadrails-b277cf28e8a6f5636d0485ab8c04ea0660444440.tar.gz
rails-b277cf28e8a6f5636d0485ab8c04ea0660444440.tar.bz2
rails-b277cf28e8a6f5636d0485ab8c04ea0660444440.zip
Allow scaffold controller to load action_orm files on demand.
Diffstat (limited to 'railties/lib/generators/named_base.rb')
-rw-r--r--railties/lib/generators/named_base.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb
index 8f44000729..0d399c876c 100644
--- a/railties/lib/generators/named_base.rb
+++ b/railties/lib/generators/named_base.rb
@@ -129,13 +129,24 @@ module Rails
#
def orm_class
@orm_class ||= begin
+ # Raise an error if the class_option :orm was not defined.
unless self.class.class_options[:orm]
raise "You need to have :orm as class option to invoke orm_class and orm_instance"
end
action_orm = "#{options[:orm].to_s.classify}::Generators::ActionORM"
- action_orm.constantize
- rescue NameError => e
+
+ # If the orm was not loaded, try to load it at "generators/orm",
+ # for example "generators/active_record" or "generators/sequel".
+ begin
+ klass = action_orm.constantize
+ rescue NameError
+ require "generators/#{options[:orm]}"
+ end
+
+ # Try once again after loading the file with success.
+ klass ||= action_orm.constantize
+ rescue Exception => e
raise Error, "Could not load #{action_orm}, skipping controller. Error: #{e.message}."
end
end