Browse files

Added resource generator which calls other generators

  • Loading branch information...
1 parent a52761b commit 808228679b163277a76c68d457da1d8e98d7f8ef @gingerhendrix committed Jul 11, 2009
View
5 generators/echonest_resource/USAGE
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
View
50 generators/echonest_resource/echonest_resource_generator.rb
@@ -0,0 +1,50 @@
+class EchonestResourceGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @name = args.shift
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.dependency "acceptance_test", [name]
+ m.dependency "unit_test", [name]
+ m.dependency "model", [name]
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |o| options[:author] = o }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
+
View
45 test/test_echonest_resource_generator.rb
@@ -0,0 +1,45 @@
+require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
+
+
+class TestEchonestResourceGenerator < Test::Unit::TestCase
+ include RubiGen::GeneratorTestHelper
+
+ def setup
+ bare_setup
+ end
+
+ def teardown
+ bare_teardown
+ end
+
+ # Some generator-related assertions:
+ # assert_generated_file(name, &block) # block passed the file contents
+ # assert_directory_exists(name)
+ # assert_generated_class(name, &block)
+ # assert_generated_module(name, &block)
+ # assert_generated_test_for(name, &block)
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
+ #
+ # Other helper methods are:
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
+
+ def test_generator_without_options
+ name = "myapp"
+ run_generator('echonest_resource', [name], sources)
+ assert_directory_exists "some/directory"
+ assert_generated_file "some_file"
+ end
+
+ private
+ def sources
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
+ ]
+ end
+
+ def generator_path
+ "generators"
+ end
+end

0 comments on commit 8082286

Please sign in to comment.