Module: Spinebox::Command

Defined in:
lib/spinebox/command.rb

Defined Under Namespace

Classes: Command

Constant Summary collapse

@@commands =
[]

Class Method Summary collapse

Class Method Details

.commandsObject

The registered commands



24
25
26
# File 'lib/spinebox/command.rb', line 24

def self.commands
  @@commands
end

.dispatchObject

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

.executeObject

Executes the matching commands



12
13
14
# File 'lib/spinebox/command.rb', line 12

def self.execute
  @@commands.each { |command| command.run! }
end

.helpObject

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.options[:type] == :option }
  
  puts ""
  
  puts "Actions:"
  @@commands.each { |command| printf "%-3s %-20s %s\n", "", command.command, command.desc if command.options[:type] == :action }
  
  puts ""
  
  puts "Generators:"
  @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.options[:type] == :generator }
  
  puts ""
  
  puts "Scaffolds:"
  @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.options[:type] == :scaffold }
end

.on(command, desc, options = {}) ⇒ Object

Registers a command to dispatch



7
8
9
# File 'lib/spinebox/command.rb', line 7

def self.on command, desc, options = {}
  @@commands << Command.new(command, desc, options, &Proc.new)
end