Module: Spinebox::Command
- Defined in:
- lib/spinebox/command.rb
Defined Under Namespace
Classes: Command
Constant Summary collapse
- @@commands =
[]
Class Method Summary collapse
-
.commands ⇒ Object
The registered commands.
-
.dispatch ⇒ Object
Dispatches the command registering block and executes the matching commands.
-
.execute ⇒ Object
Executes the matching commands.
-
.help ⇒ Object
Combines the information of all registered commands and concatenates them to a string.
-
.on(command, desc, options = {}) ⇒ Object
Registers a command to dispatch.
Class Method Details
.commands ⇒ Object
The registered commands
24 25 26 |
# File 'lib/spinebox/command.rb', line 24 def self.commands @@commands end |
.dispatch ⇒ Object
Dispatches the command registering block and executes the matching commands
17 18 19 20 21 |
# File 'lib/spinebox/command.rb', line 17 def self.dispatch raise "Nothing to dispatch" unless block_given? self.module_exec(&Proc.new) execute end |
.execute ⇒ Object
Executes the matching commands
12 13 14 |
# File 'lib/spinebox/command.rb', line 12 def self.execute @@commands.each { |command| command.run! } end |
.help ⇒ Object
Combines the information of all registered commands and concatenates them to a string
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spinebox/command.rb', line 29 def self.help puts "Usage:" printf "%-3s %s\n\n", "", "spinebox new APP_PATH" puts "Options:" @@commands.each { |command| printf "%-3s %-20s %s\n", "", command.command, command.desc if command.[:type] == :option } puts "" puts "Actions:" @@commands.each { |command| printf "%-3s %-20s %s\n", "", command.command, command.desc if command.[:type] == :action } puts "" puts "Generators:" @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.[:type] == :generator } puts "" puts "Scaffolds:" @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.[:type] == :scaffold } end |