Class: Shacho::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/shacho/runner.rb

Class Method Summary collapse

Class Method Details

.delegate_command(options) ⇒ Object

TODO include active support?



27
28
29
30
31
32
33
# File 'lib/shacho/runner.rb', line 27

def delegate_command(options)
  if options["action"] == "help"
    Shacho::Util.help
  else
    Shacho::Account.send(options["action"], options["params"])
  end
end

.error(message) ⇒ Object

Raises:

  • (RuntimeError)


22
23
24
# File 'lib/shacho/runner.rb', line 22

def error(message)
  raise RuntimeError, message
end

.parse_options(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shacho/runner.rb', line 10

def parse_options(args)
  options = {}
  value = args.shift
  if COMMANDS.include?(value)
    options["action"] = value
  else
    error "Run shacho help for usage"
  end
  options["params"] = args
  return options
end

.run!(*args) ⇒ Object



4
5
6
7
8
# File 'lib/shacho/runner.rb', line 4

def run!(*args)
  options = parse_options(args)
  delegate_command(options)
  return 0
end