Class: Nodectl::Repository
- Inherits:
-
Object
- Object
- Nodectl::Repository
- Defined in:
- lib/nodectl/repository.rb
Constant Summary collapse
- VCSError =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #current_version ⇒ Object
- #fetch ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #pull ⇒ Object
- #switch_version(version) ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(path) ⇒ Repository
Returns a new instance of Repository.
4 5 6 |
# File 'lib/nodectl/repository.rb', line 4 def initialize(path) @path = path end |
Class Method Details
.clone(from, to) ⇒ Object
57 58 59 60 61 |
# File 'lib/nodectl/repository.rb', line 57 def clone(from, to) FileUtils.mkdir_p(to) ret, out = shell_run("git clone #{from} #{to}") new(to) end |
.shell_run(command, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nodectl/repository.rb', line 63 def shell_run(command, = {}) command = "#{command} 2>&1" Nodectl.logger.info "repository: run command '#{command}'" process = IO.popen(command) out = process.read process.close ret = $? if ret != 0 && ![:ignore_status] raise VCSError, "exit status: #{ret.exitstatus}" end [ret, out] end |
Instance Method Details
#current_version ⇒ Object
8 9 10 11 |
# File 'lib/nodectl/repository.rb', line 8 def current_version ret, out = shell_git("log -1 --pretty=format:%H\\ %ci\\ %s") parse_version(out) end |
#fetch ⇒ Object
30 31 32 |
# File 'lib/nodectl/repository.rb', line 30 def fetch shell_git("fetch") end |
#pull ⇒ Object
34 35 36 37 |
# File 'lib/nodectl/repository.rb', line 34 def pull shell_git("checkout master") shell_git("pull") end |
#switch_version(version) ⇒ Object
13 14 15 |
# File 'lib/nodectl/repository.rb', line 13 def switch_version(version) shell_git("checkout -f #{version}") end |
#versions ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nodectl/repository.rb', line 17 def versions fetch ret, out = shell_git("log --all --pretty=format:%H\\ %ci\\ %s") result = [] out.each_line do |line| result << parse_version(line) end result end |