aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2006-05-23 17:15:15 +0000
committerMarcel Molina <marcel@vernix.org>2006-05-23 17:15:15 +0000
commit3115c425a0e65963f2fde5b297676d2cbd505f59 (patch)
tree9929b48b5de296cc8d5edca1abf8176451eb0021 /railties
parent5108fa87af09f17a1eba0ffd101119bec3f5fcef (diff)
downloadrails-3115c425a0e65963f2fde5b297676d2cbd505f59.tar.gz
rails-3115c425a0e65963f2fde5b297676d2cbd505f59.tar.bz2
rails-3115c425a0e65963f2fde5b297676d2cbd505f59.zip
Add generator files...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4365 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails_generator/generators/components/observer/USAGE15
-rw-r--r--railties/lib/rails_generator/generators/components/observer/observer_generator.rb16
-rw-r--r--railties/lib/rails_generator/generators/components/observer/templates/observer.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb10
4 files changed, 43 insertions, 0 deletions
diff --git a/railties/lib/rails_generator/generators/components/observer/USAGE b/railties/lib/rails_generator/generators/components/observer/USAGE
new file mode 100644
index 0000000000..8abaf3678f
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/observer/USAGE
@@ -0,0 +1,15 @@
+Description:
+ The observer generator creates stubs for a new observer.
+
+ The generator takes a observer name as its argument. The observer name may be
+ given in CamelCase or under_score and should not be suffixed with 'Observer'.
+
+ The generator creates a observer class in app/models and a test suite in
+ test/unit.
+
+Example:
+ ./script/generate observer Account
+
+ This will create an Account observer:
+ Observer: app/models/account_observer.rb
+ Test: test/unit/account_observer_test.rb
diff --git a/railties/lib/rails_generator/generators/components/observer/observer_generator.rb b/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
new file mode 100644
index 0000000000..18fbd32b75
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
@@ -0,0 +1,16 @@
+class ObserverGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ # Check for class naming collisions.
+ m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
+
+ # Observer, and test directories.
+ m.directory File.join('app/models', class_path)
+ m.directory File.join('test/unit', class_path)
+
+ # Observer class and unit test fixtures.
+ m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
+ end
+ end
+end
diff --git a/railties/lib/rails_generator/generators/components/observer/templates/observer.rb b/railties/lib/rails_generator/generators/components/observer/templates/observer.rb
new file mode 100644
index 0000000000..b9a3004161
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/observer/templates/observer.rb
@@ -0,0 +1,2 @@
+class <%= class_name %>Observer < ActiveRecord::Observer
+end
diff --git a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb
new file mode 100644
index 0000000000..68a8cf065b
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
+
+class <%= class_name %>ObserverTest < Test::Unit::TestCase
+ fixtures :<%= table_name %>
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end