Class: Trent

Inherits:
Object
  • Object
show all
Defined in:
lib/trent.rb

Overview

Communicate with all of the Trent library with this class.

Instance Method Summary collapse

Constructor Details

#initialize(color = :blue) ⇒ Trent

Returns a new instance of Trent.



9
10
11
12
13
14
# File 'lib/trent.rb', line 9

def initialize(color = :blue)
  Log.fatal('Trent is designed to run on Travis-CI builds. Run it on Travis-CI.') unless ENV['HAS_JOSH_K_SEAL_OF_APPROVAL']

  @color = color
  @sh = Sh.new
end

Instance Method Details

#config_github(api_key) ⇒ Object

Configure how to communicate with GitHub



22
23
24
# File 'lib/trent.rb', line 22

def config_github(api_key)
  @github = GitHub.new(api_key)
end

#config_ssh(username, host, password = nil) ⇒ Object

Configure how to run remote SSH commmands on server.



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

def config_ssh(username, host, password = nil)
  @ssh = SSH.new(username, host, password: password)
end

#githubObject

Get instance of GitHub class to run commands against GitHub



56
57
58
59
# File 'lib/trent.rb', line 56

def github
  Log.fatal('You did not configure GitHub yet.') unless @github
  @github
end

#sh(command, fail_non_success = true) ⇒ Object

Run local bash command



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trent.rb', line 39

def sh(command, fail_non_success = true)
  puts command.colorize(@color)

  result = @sh.run(command)

  unless result[:result]
    if fail_non_success
      Log.fatal('Command failed with a non 0 exit status.')
    else
      Log.warning('Command failed with a non 0 exit status.')
    end
  end

  result
end

#ssh(command, fail_non_success = true) ⇒ Object

Run ssh command



27
28
29
30
31
32
33
34
35
36
# File 'lib/trent.rb', line 27

def ssh(command, fail_non_success = true)
  Log.fatal('You did not configure SSH yet.') unless @ssh

  puts command.colorize(@color)
  result = @ssh.run(command)

  Log.fatal('Command failed with a non 0 exit status.') if !result[:result] && fail_non_success

  result
end