Class: MisterBin::Runner

Inherits:
Object
  • Object
show all
Includes:
Colsole
Defined in:
lib/mister_bin/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
# File 'lib/mister_bin/runner.rb', line 9

def initialize(opts={})
  @header = opts[:header]
  @footer = opts[:footer]
  @version = opts[:version]
  @commands = opts[:commands] || {}
  @handler = opts[:handler]
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



7
8
9
# File 'lib/mister_bin/runner.rb', line 7

def commands
  @commands
end

Returns the value of attribute footer.



7
8
9
# File 'lib/mister_bin/runner.rb', line 7

def footer
  @footer
end

#handlerObject (readonly)

Returns the value of attribute handler.



7
8
9
# File 'lib/mister_bin/runner.rb', line 7

def handler
  @handler
end

#headerObject (readonly)

Returns the value of attribute header.



7
8
9
# File 'lib/mister_bin/runner.rb', line 7

def header
  @header
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/mister_bin/runner.rb', line 7

def version
  @version
end

Instance Method Details

#route(key, to:) ⇒ Object



17
18
19
# File 'lib/mister_bin/runner.rb', line 17

def route(key, to:)
  commands[key] = to
end

#route_all(to:) ⇒ Object



21
22
23
# File 'lib/mister_bin/runner.rb', line 21

def route_all(to:)
  @handler = to
end

#run(argv = []) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mister_bin/runner.rb', line 25

def run(argv=[])
  if handler
    handler.execute argv
  elsif argv.empty?
    show_subs
  elsif argv == ['--version'] and version
    puts version
    return 1
  else
    execute argv
  end
end