Parent

Included Modules

RubiGen::Scripts::Base

Generator scripts handle command-line invocation. Each script responds to an invoke! class method which handles option parsing and generator invocation.

Attributes

stdout[R]

Public Instance Methods

run(args = [], runtime_options = {}) click to toggle source

Run the generator script. Takes an array of unparsed arguments and a hash of parsed arguments, takes the generator as an option or first remaining argument, and invokes the requested command.

    # File lib/rubigen/scripts.rb, line 17
17:       def run(args = [], runtime_options = {})
18:         @stdout = runtime_options[:stdout] || $stdout
19:         begin
20:           parse!(args.dup, runtime_options)
21:         rescue OptionParser::InvalidOption => e
22:           # Don't cry, script. Generators want what you think is invalid.
23:         end
24: 
25:         # Generator name is the only required option.
26:         unless options[:generator]
27:           usage if args.empty?
28:           options[:generator] ||= args.shift
29:         end
30: 
31:         # Look up generator instance and invoke command on it.
32:         RubiGen::Base.instance(options[:generator], args, options).command(options[:command]).invoke!
33:       rescue => e
34:         stdout.puts e
35:         stdout.puts "  #{e.backtrace.join("\n  ")}\n" if options[:backtrace]
36:         raise SystemExit unless options[:no_exit]
37:       end

Protected Instance Methods

usage_message() click to toggle source
    # File lib/rubigen/scripts.rb, line 45
45:         def usage_message
46:           usage = "\nInstalled Generators\n"
47:           RubiGen::Base.sources.inject([]) do |mem, source|
48:             # Using an association list instead of a hash to preserve order,
49:             # for aesthetic reasons more than anything else.
50:             label = source.label.to_s.capitalize
51:             pair = mem.assoc(label)
52:             mem << (pair = [label, []]) if pair.nil?
53:             pair[1] |= source.names(:visible)
54:             mem
55:           end.each do |label, names|
56:             usage << "  #{label}: #{names.join(', ')}\n" unless names.empty?
57:           end
58: 
59:           # TODO - extensible blurbs for rails/newgem/adhearsion etc
60:           # e.g. for rails http://github.com/rails/rails/tree/daee6fd92ac16878f6806c3382a9e74592aa9656/railties/lib/rails_generator/scripts.rb#L50-74
61:           usage << More are available at http://rubigen.rubyforge.org/
62: 
63:           usage << Run generate with no arguments for usage information     #{$0} test_unit
64:           return usage
65:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.