Class: Harbor::Generator
- Inherits:
-
Object
- Object
- Harbor::Generator
- Defined in:
- lib/harbor/generator.rb,
lib/harbor/generator/help.rb,
lib/harbor/generator/setup.rb
Defined Under Namespace
Classes: GeneratorArgumentError, GeneratorError, HelpCommand, SetupCommand, UnknownCommandError
Constant Summary collapse
- @@generators =
{}
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#command ⇒ Object
Returns the value of attribute command.
-
#description ⇒ Object
Returns the value of attribute description.
-
#help ⇒ Object
Returns the value of attribute help.
-
#klass ⇒ Object
Returns the value of attribute klass.
Class Method Summary collapse
- .generators ⇒ Object
- .register(app, command, klass, description = "", help = "") ⇒ Object
- .run(app, command, options = []) ⇒ Object
- .usage(app) ⇒ Object
Instance Method Summary collapse
-
#initialize(app, command, klass, description, help) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(app, command, klass, description, help) ⇒ Generator
Returns a new instance of Generator.
14 15 16 |
# File 'lib/harbor/generator.rb', line 14 def initialize(app, command, klass, description, help) @app, @command, @klass, @description, @help = app, command, klass, description, help end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
12 13 14 |
# File 'lib/harbor/generator.rb', line 12 def app @app end |
#command ⇒ Object
Returns the value of attribute command.
12 13 14 |
# File 'lib/harbor/generator.rb', line 12 def command @command end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/harbor/generator.rb', line 12 def description @description end |
#help ⇒ Object
Returns the value of attribute help.
12 13 14 |
# File 'lib/harbor/generator.rb', line 12 def help @help end |
#klass ⇒ Object
Returns the value of attribute klass.
12 13 14 |
# File 'lib/harbor/generator.rb', line 12 def klass @klass end |
Class Method Details
.generators ⇒ Object
48 49 50 |
# File 'lib/harbor/generator.rb', line 48 def self.generators @@generators end |
.register(app, command, klass, description = "", help = "") ⇒ Object
44 45 46 |
# File 'lib/harbor/generator.rb', line 44 def self.register(app, command, klass, description = "", help = "") @@generators["#{app}:#{command}"] = new(app, command, klass, description, help) end |
.run(app, command, options = []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/harbor/generator.rb', line 18 def self.run(app, command, = []) executor = if generator = @@generators["#{app}:#{command}"] generator.klass.new() else puts usage(app) exit(1) end executor.run end |
.usage(app) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/harbor/generator.rb', line 30 def self.usage(app) usage = [] usage << "Usage #{app} command [options]" usage << "" usage << "Available commands:" @@generators.select { |key,| key =~ /^#{app}/ }.sort.each do |key, generator| usage << "%12s %s" % [generator.command, generator.description] end usage end |