Module: Terrafile::Helper
- Defined in:
- lib/terrafile/helper.rb
Class Method Summary collapse
- .clone(source, destination) ⇒ Object
- .dir_exists?(path) ⇒ Boolean
- .file_exists?(path) ⇒ Boolean
- .pull_repo ⇒ Object
- .repo_up_to_date?(version) ⇒ Boolean
- .run!(command) ⇒ Object
- .run_with_output(command) ⇒ Object
Class Method Details
.clone(source, destination) ⇒ Object
28 29 30 |
# File 'lib/terrafile/helper.rb', line 28 def self.clone(source, destination) run!("git clone #{source} #{destination} 1> /dev/null") end |
.dir_exists?(path) ⇒ Boolean
32 33 34 |
# File 'lib/terrafile/helper.rb', line 32 def self.dir_exists?(path) Dir.exist?(path) end |
.file_exists?(path) ⇒ Boolean
36 37 38 |
# File 'lib/terrafile/helper.rb', line 36 def self.file_exists?(path) File.exist?(path) end |
.pull_repo ⇒ Object
46 47 48 |
# File 'lib/terrafile/helper.rb', line 46 def self.pull_repo run!('git pull 1> /dev/null') end |
.repo_up_to_date?(version) ⇒ Boolean
40 41 42 43 44 |
# File 'lib/terrafile/helper.rb', line 40 def self.repo_up_to_date?(version) current_tag = run_with_output('git describe --tags').tr("\n", '') current_hash = run_with_output('git rev-parse HEAD').tr("\n", '') [current_tag, current_hash].include? version end |
.run!(command) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/terrafile/helper.rb', line 3 def self.run!(command) begin _stdout, stderr, status = Open3.capture3(command) rescue Errno::ENOENT => error raise Error, "'#{command}' failed (#{error})" end unless status.success? raise Error, "'#{command}' failed with exit code #{status.exitstatus} " \ "(#{stderr.chomp})" end true end |
.run_with_output(command) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/terrafile/helper.rb', line 18 def self.run_with_output(command) begin stdout, _stderr, _status = Open3.capture3(command) rescue Errno::ENOENT => error raise Error, "'#{command}' failed (#{error})" end stdout.chomp end |