diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/generators.rb | 1 | ||||
-rw-r--r-- | railties/lib/generators/active_record.rb | 8 | ||||
-rw-r--r-- | railties/lib/generators/active_record/observer/observer_generator.rb | 11 | ||||
-rw-r--r-- | railties/lib/generators/active_record/observer/templates/observer.rb (renamed from railties/lib/generators/rails/observer/templates/observer.rb) | 0 | ||||
-rw-r--r-- | railties/lib/generators/base.rb | 9 | ||||
-rw-r--r-- | railties/lib/generators/rails/observer/USAGE | 5 | ||||
-rw-r--r-- | railties/lib/generators/rails/observer/observer_generator.rb | 8 |
7 files changed, 28 insertions, 14 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index f094a1f062..f1b0d694af 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -12,6 +12,7 @@ require 'rails/version' unless defined?(Rails::VERSION) require 'generators/base' require 'generators/named_base' +require 'generators/active_record' require 'generators/erb' require 'generators/test_unit' diff --git a/railties/lib/generators/active_record.rb b/railties/lib/generators/active_record.rb new file mode 100644 index 0000000000..be5d033868 --- /dev/null +++ b/railties/lib/generators/active_record.rb @@ -0,0 +1,8 @@ +require 'generators/named_base' + +module ActiveRecord + module Generators + class Base < Rails::Generators::NamedBase + end + end +end diff --git a/railties/lib/generators/active_record/observer/observer_generator.rb b/railties/lib/generators/active_record/observer/observer_generator.rb new file mode 100644 index 0000000000..5bc9da34d1 --- /dev/null +++ b/railties/lib/generators/active_record/observer/observer_generator.rb @@ -0,0 +1,11 @@ +module ActiveRecord + module Generators + class ObserverGenerator < Base + check_class_collision :suffix => "Observer" + + def create_observer_file + template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb") + end + end + end +end diff --git a/railties/lib/generators/rails/observer/templates/observer.rb b/railties/lib/generators/active_record/observer/templates/observer.rb index b9a3004161..b9a3004161 100644 --- a/railties/lib/generators/rails/observer/templates/observer.rb +++ b/railties/lib/generators/active_record/observer/templates/observer.rb diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index 10bd1ea4af..5c3b3f0782 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -3,9 +3,10 @@ require 'generators/actions' module Rails module Generators DEFAULTS = { + :orm => 'active_record', + :helper => true, :test_framework => 'test_unit', - :template_engine => 'erb', - :helper => true + :template_engine => 'erb' } class Error < Thor::Error @@ -41,7 +42,7 @@ module Rails # def self.namespace(name=nil) return super if name - @namespace ||= "#{base_name}:generators:#{generator_name}" + @namespace ||= super.sub(/_generator$/, '') end # Invoke a generator based on the value supplied by the user to the @@ -207,7 +208,7 @@ module Rails def self.generator_name @generator_name ||= begin klass_name = self.name.split('::').last - klass_name.gsub!(/Generator$/, '') + klass_name.sub!(/Generator$/, '') klass_name.underscore end end diff --git a/railties/lib/generators/rails/observer/USAGE b/railties/lib/generators/rails/observer/USAGE index 197b5d6e4a..9a20f55a89 100644 --- a/railties/lib/generators/rails/observer/USAGE +++ b/railties/lib/generators/rails/observer/USAGE @@ -2,12 +2,11 @@ Description: Stubs out a new observer. Pass the observer name, either CamelCased or under_scored, as an argument. - The generator creates an observer class in app/models and invokes the - configured test framework. + This generator only invokes your ORM and test framework generators. Example: `./script/generate observer Account` - creates an Account observer and invoke the test framework: + For ActiveRecord and TestUnit it creates: Observer: app/models/account_observer.rb TestUnit: test/unit/account_observer_test.rb diff --git a/railties/lib/generators/rails/observer/observer_generator.rb b/railties/lib/generators/rails/observer/observer_generator.rb index ad058a3172..b336cf41a0 100644 --- a/railties/lib/generators/rails/observer/observer_generator.rb +++ b/railties/lib/generators/rails/observer/observer_generator.rb @@ -1,13 +1,7 @@ module Rails module Generators class ObserverGenerator < NamedBase - check_class_collision :suffix => "Observer" - - def create_observer_file - template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb") - end - - invoke_for :test_framework + invoke_for :orm, :test_framework end end end |