Class: Hub::Runner
- Inherits:
-
Object
- Object
- Hub::Runner
- Defined in:
- lib/hub/runner.rb
Overview
The Hub runner expects to be initialized with ‘ARGV` and primarily exists to run a git command.
The actual functionality, that is, the code it runs when it needs to augment a git command, is kept in the ‘Hub::Commands` module.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
-
.execute(*args) ⇒ Object
Shortcut.
Instance Method Summary collapse
-
#after ⇒ Object
Returns the current after callback, which (if set) is run after the target git command.
-
#command ⇒ Object
A string representation of the git command we would run if #execute were called.
-
#execute ⇒ Object
Runs the target git command with an optional callback.
-
#execute_with_after_callback ⇒ Object
Runs the target git command then executes the ‘after` callback.
-
#initialize(*args) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(*args) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hub/runner.rb', line 10 def initialize(*args) @args = Args.new(args) # Hack to emulate git-style @args.unshift 'help' if @args.grep(/^[^-]|version/).empty? if Commands.respond_to?(@args[0]) Commands.send(@args[0], @args) end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/hub/runner.rb', line 8 def args @args end |
Class Method Details
.execute(*args) ⇒ Object
Shortcut
22 23 24 |
# File 'lib/hub/runner.rb', line 22 def self.execute(*args) new(*args).execute end |
Instance Method Details
#after ⇒ Object
Returns the current after callback, which (if set) is run after the target git command.
See the ‘Hub::Args` class for more information on the `after` callback.
31 32 33 |
# File 'lib/hub/runner.rb', line 31 def after args.after.to_s end |
#command ⇒ Object
A string representation of the git command we would run if #execute were called.
37 38 39 |
# File 'lib/hub/runner.rb', line 37 def command args.to_exec.join(' ') end |
#execute ⇒ Object
Runs the target git command with an optional callback. Replaces the current process.
43 44 45 46 47 48 49 |
# File 'lib/hub/runner.rb', line 43 def execute if args.after? execute_with_after_callback else exec(*args.to_exec) end end |
#execute_with_after_callback ⇒ Object
Runs the target git command then executes the ‘after` callback.
See the ‘Hub::Args` class for more information on the `after` callback.
55 56 57 58 59 60 61 62 63 |
# File 'lib/hub/runner.rb', line 55 def execute_with_after_callback after = args.after if system(*args.to_exec) after.respond_to?(:call) ? after.call : exec(after) exit else exit 1 end end |