aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-06-27 11:05:43 +0200
committerJosé Valim <jose.valim@gmail.com>2009-06-27 21:29:59 +0200
commitff48e23a4eb9f4a5fd3a02addb398499fb3c1455 (patch)
tree373d1db11fec7fb083135586924cc8847f0f832b
parent85ff67ce4c0e95de9b855af7f7e7fbab7f7726de (diff)
downloadrails-ff48e23a4eb9f4a5fd3a02addb398499fb3c1455.tar.gz
rails-ff48e23a4eb9f4a5fd3a02addb398499fb3c1455.tar.bz2
rails-ff48e23a4eb9f4a5fd3a02addb398499fb3c1455.zip
Make Observer generator agnostic.
-rw-r--r--railties/lib/generators.rb1
-rw-r--r--railties/lib/generators/active_record.rb8
-rw-r--r--railties/lib/generators/active_record/observer/observer_generator.rb11
-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.rb9
-rw-r--r--railties/lib/generators/rails/observer/USAGE5
-rw-r--r--railties/lib/generators/rails/observer/observer_generator.rb8
-rw-r--r--railties/test/generators/observer_generator_test.rb1
8 files changed, 29 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
diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb
index 85c95c9dc7..780c854d85 100644
--- a/railties/test/generators/observer_generator_test.rb
+++ b/railties/test/generators/observer_generator_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'generators/generators_test_helper'
+require 'generators/active_record/observer/observer_generator'
require 'generators/rails/observer/observer_generator'
require 'generators/test_unit/observer/observer_generator'