Class: Rvm2::Shell::Command::Base
- Inherits:
-
Object
- Object
- Rvm2::Shell::Command::Base
- Includes:
- Hooks
- Defined in:
- lib/rvm2/shell/command/base.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #aborted? ⇒ Boolean
- #duration ⇒ Object
- #execute(runner) ⇒ Object
- #failed? ⇒ Boolean
- #finish(status) ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #start ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/rvm2/shell/command/base.rb', line 11 def initialize(*args) @command = args end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/rvm2/shell/command/base.rb', line 9 def command @command end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/rvm2/shell/command/base.rb', line 9 def status @status end |
Instance Method Details
#aborted? ⇒ Boolean
42 43 44 |
# File 'lib/rvm2/shell/command/base.rb', line 42 def aborted? @status.nil? end |
#duration ⇒ Object
27 28 29 30 |
# File 'lib/rvm2/shell/command/base.rb', line 27 def duration return nil if @started.nil? || @finished.nil? @finished - @started end |
#execute(runner) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/rvm2/shell/command/base.rb', line 32 def execute(runner) start status = runner.execute(to_s) do |out, err| run_hook(:on_stdout, out) if out run_hook(:on_stderr, err) if err end ensure finish(status) # nil if not called end |
#failed? ⇒ Boolean
50 51 52 |
# File 'lib/rvm2/shell/command/base.rb', line 50 def failed? !aborted? && !success? end |
#finish(status) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/rvm2/shell/command/base.rb', line 20 def finish(status) @finished = Time.now @status = status run_hook(:on_finish, @finished, @status) @status end |
#start ⇒ Object
15 16 17 18 |
# File 'lib/rvm2/shell/command/base.rb', line 15 def start @started = Time.now run_hook(:on_start, @started) end |
#success? ⇒ Boolean
46 47 48 |
# File 'lib/rvm2/shell/command/base.rb', line 46 def success? @status == 0 end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/rvm2/shell/command/base.rb', line 54 def to_s args.map{|a| "\"#{a}\""}.join(" ") end |