Class: MisterBin::Runner
- Inherits:
-
Object
- Object
- MisterBin::Runner
- Includes:
- Colsole
- Defined in:
- lib/mister_bin/runner.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#footer ⇒ Object
readonly
Returns the value of attribute footer.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Runner
constructor
A new instance of Runner.
- #route(key, to:) ⇒ Object
- #route_all(to:) ⇒ Object
- #run(argv = []) ⇒ Object
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
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
7 8 9 |
# File 'lib/mister_bin/runner.rb', line 7 def commands @commands end |
#footer ⇒ Object (readonly)
Returns the value of attribute footer.
7 8 9 |
# File 'lib/mister_bin/runner.rb', line 7 def @footer end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
7 8 9 |
# File 'lib/mister_bin/runner.rb', line 7 def handler @handler end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
7 8 9 |
# File 'lib/mister_bin/runner.rb', line 7 def header @header end |
#version ⇒ Object (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 37 38 |
# File 'lib/mister_bin/runner.rb', line 25 def run(argv=[]) if handler handler.execute argv elsif argv.empty? show_subs elsif argv == ['--help'] or argv == ['-h'] show_help elsif version and (argv == ['--version'] or argv == ['-v']) puts version return 1 else execute argv end end |