diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/generators.rb | 1 | ||||
-rw-r--r-- | railties/lib/generators/named_base.rb | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index 83f1847598..e7495e8036 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -12,7 +12,6 @@ require 'rails/version' unless defined?(Rails::VERSION) require 'generators/base' require 'generators/named_base' -require 'generators/active_record' # We will need ActionORM from ActiveRecord, but just it. module Rails module Generators 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 |