From 3115c425a0e65963f2fde5b297676d2cbd505f59 Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Tue, 23 May 2006 17:15:15 +0000 Subject: Add generator files... git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4365 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../rails_generator/generators/components/observer/USAGE | 15 +++++++++++++++ .../generators/components/observer/observer_generator.rb | 16 ++++++++++++++++ .../generators/components/observer/templates/observer.rb | 2 ++ .../components/observer/templates/unit_test.rb | 10 ++++++++++ 4 files changed, 43 insertions(+) create mode 100644 railties/lib/rails_generator/generators/components/observer/USAGE create mode 100644 railties/lib/rails_generator/generators/components/observer/observer_generator.rb create mode 100644 railties/lib/rails_generator/generators/components/observer/templates/observer.rb create mode 100644 railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb (limited to 'railties/lib/rails_generator/generators') 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 -- cgit v1.2.3