Class: Mycommands::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/mycommands/application.rb

Constant Summary collapse

OPTIONS =
[
  {short: 'v', verbose: 'version', route: [:Application, :print_version], input: false, description: 'Prints the version'},
  {short: 's', verbose: 'sort', route: [:Application, :sort_yaml_files], input: false, description: 'Sorts categories.yml and commands.yml alphabetically'},
  {short: 'c', verbose: 'copy', route: [:Application, :copy_yaml_files], input: false, description: 'Copies categories.yml and commands.yml to ~/Mycommands/ so that they overrides the default ones'},
  {short: 'h', verbose: 'help', route: [:Application, :help], input: false, description: 'Shows this help'}
]

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



10
11
12
# File 'lib/mycommands/application.rb', line 10

def initialize
  @router = Factory::get(:Router)
end

Instance Method Details

#dispatch(args) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/mycommands/application.rb', line 20

def dispatch args
  controller, action, input= args.map &:to_s
  puts "Dispatching: #{controller}, #{action}, #{input}" if DEBUG
  if input.nil?
    Factory::get(controller+'Controller').send action
  else
    Factory::get(controller+'Controller').send action, input
  end
end

#runObject



14
15
16
17
18
# File 'lib/mycommands/application.rb', line 14

def run
  route, input = check_options
  dispatch route
  get_input if input
end