Class: Rvm2::Shell::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/rvm2/shell/command/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/rvm2/shell/command/base.rb', line 9

def command
  @command
end

#statusObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/rvm2/shell/command/base.rb', line 42

def aborted?
  @status.nil?
end

#durationObject



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

Returns:

  • (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

#startObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/rvm2/shell/command/base.rb', line 46

def success?
  @status == 0
end

#to_sObject



54
55
56
# File 'lib/rvm2/shell/command/base.rb', line 54

def to_s
  args.map{|a| "\"#{a}\""}.join(" ")
end