diff options
Diffstat (limited to 'railties/lib/generators/rails/observer')
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 |