aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/rails/observer
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-06-25 11:24:35 +0200
committerJosé Valim <jose.valim@gmail.com>2009-06-25 11:24:35 +0200
commit4573fd2e06ee9b5a68f84f085f0a10c9ad6f129b (patch)
tree5564b3eea0676aead0bf502a13f02ae1d73fd541 /railties/lib/generators/rails/observer
parenteaef1ee09c4bd2ed11722660fddf9b4e7e1384cc (diff)
downloadrails-4573fd2e06ee9b5a68f84f085f0a10c9ad6f129b.tar.gz
rails-4573fd2e06ee9b5a68f84f085f0a10c9ad6f129b.tar.bz2
rails-4573fd2e06ee9b5a68f84f085f0a10c9ad6f129b.zip
Added observer generator.
Diffstat (limited to 'railties/lib/generators/rails/observer')
-rw-r--r--railties/lib/generators/rails/observer/USAGE13
-rw-r--r--railties/lib/generators/rails/observer/observer_generator.rb14
-rw-r--r--railties/lib/generators/rails/observer/templates/observer.rb2
3 files changed, 29 insertions, 0 deletions
diff --git a/railties/lib/generators/rails/observer/USAGE b/railties/lib/generators/rails/observer/USAGE
new file mode 100644
index 0000000000..fca4907ca6
--- /dev/null
+++ b/railties/lib/generators/rails/observer/USAGE
@@ -0,0 +1,13 @@
+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 a unit test in
+ the configured test framework.
+
+Example:
+ `./script/generate observer Account`
+
+ creates an Account observer and invoke the test framework:
+ 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
new file mode 100644
index 0000000000..9a5253a0ad
--- /dev/null
+++ b/railties/lib/generators/rails/observer/observer_generator.rb
@@ -0,0 +1,14 @@
+module Rails
+ module Generators
+ class ObserverGenerator < NamedBase
+ # TODO Check class collisions
+ # class_collisions "#{class_name}Observer", "#{class_name}ObserverTest"
+
+ def create_observer_file
+ template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
+ end
+
+ add_and_invoke_test_framework_option!
+ end
+ end
+end
diff --git a/railties/lib/generators/rails/observer/templates/observer.rb b/railties/lib/generators/rails/observer/templates/observer.rb
new file mode 100644
index 0000000000..b9a3004161
--- /dev/null
+++ b/railties/lib/generators/rails/observer/templates/observer.rb
@@ -0,0 +1,2 @@
+class <%= class_name %>Observer < ActiveRecord::Observer
+end