Class: Trent
- Inherits:
-
Object
- Object
- Trent
- Defined in:
- lib/trent.rb
Overview
Communicate with all of the Trent library with this class.
Instance Method Summary collapse
-
#config_github(api_key) ⇒ Object
Configure how to communicate with GitHub.
-
#config_ssh(username, host, options = nil) ⇒ Object
Configure how to run remote SSH commmands on server.
-
#config_travis(api_key, private_repo) ⇒ Object
Configure how to communicate with Travis.
-
#github ⇒ Object
Get instance of GitHub class to run commands against GitHub.
-
#initialize(params = {}) ⇒ Trent
constructor
Initialize Trent instance.
-
#path(command, path) ⇒ Object
While working with bash commands, some commands are not added to the path.
-
#sh(command, fail_non_success: true) ⇒ Object
Run local bash command.
-
#ssh(command, fail_non_success: true) ⇒ Object
Run ssh command.
-
#travis ⇒ Object
Get instance of GitHub class to run commands against GitHub.
Constructor Details
#initialize(params = {}) ⇒ Trent
Initialize Trent instance. color - Color of shell output you want Trent to use. local - Run Trent locally on your own machine instead of a CI server.
16 17 18 19 20 21 22 23 24 |
# File 'lib/trent.rb', line 16 def initialize(params = {}) running_local = params.fetch(:local, false) Log.fatal('Trent is designed to run on Travis-CI builds. Run it on Travis-CI.') unless TravisCI.running_on_travis? || running_local @color = params.fetch(:color, :blue) @sh = Sh.new @paths = {} end |
Instance Method Details
#config_github(api_key) ⇒ Object
Configure how to communicate with GitHub
32 33 34 |
# File 'lib/trent.rb', line 32 def config_github(api_key) @github = GitHub.new(api_key) end |
#config_ssh(username, host, options = nil) ⇒ Object
Configure how to run remote SSH commmands on server.
27 28 29 |
# File 'lib/trent.rb', line 27 def config_ssh(username, host, = nil) @ssh = SSH.new(username, host, ) end |
#config_travis(api_key, private_repo) ⇒ Object
Configure how to communicate with Travis
37 38 39 |
# File 'lib/trent.rb', line 37 def config_travis(api_key, private_repo) @travis = TravisCI.new(api_key: api_key, private_repo: private_repo) end |
#github ⇒ Object
Get instance of GitHub class to run commands against GitHub
81 82 83 84 |
# File 'lib/trent.rb', line 81 def github Log.fatal('You did not configure GitHub yet.') unless @github @github end |
#path(command, path) ⇒ Object
While working with bash commands, some commands are not added to the path. That’s annoying. Convenient method to assign a command to a path for replacing. Example: ci.path(“docker-compose”, “/opt/bin/docker-compose”) Now, when you use ci.sh(“docker-compose -f … up -d”), it will run “/opt/bin/docker-compose -f … up -d” instead.
46 47 48 |
# File 'lib/trent.rb', line 46 def path(command, path) @paths[command] = path end |
#sh(command, fail_non_success: true) ⇒ Object
Run local bash command
64 65 66 67 68 69 70 71 72 |
# File 'lib/trent.rb', line 64 def sh(command, fail_non_success: true) command = Command.path_replace(command, @paths) puts command.colorize(@color) result = @sh.run(command) process_shell_result(result, fail_non_success) result end |
#ssh(command, fail_non_success: true) ⇒ Object
Run ssh command
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trent.rb', line 51 def ssh(command, fail_non_success: true) command = Command.path_replace(command, @paths) Log.fatal('You did not configure SSH yet.') unless @ssh puts command.colorize(@color) result = @ssh.run(command) process_shell_result(result, fail_non_success) result end |
#travis ⇒ Object
Get instance of GitHub class to run commands against GitHub
75 76 77 78 |
# File 'lib/trent.rb', line 75 def travis Log.fatal('You did not configure Travis yet.') unless @travis @travis end |