class Rrm::GemfileLock
Constants
- FILENAME
- GEMFILE
- TIMEOUT_SECONDS
Attributes
content[RW]
git[RW]
new_version[RW]
update_gems[RW]
Public Class Methods
new(git, update_gems)
click to toggle source
# File lib/rrm/filehandlers/gemfile_lock.rb, line 11 def initialize(git, update_gems) @content = File.read("#{git.dir.path}/#{FILENAME}") @git = git @update_gems = update_gems rescue @content = nil end
Public Instance Methods
update!(new_version)
click to toggle source
# File lib/rrm/filehandlers/gemfile_lock.rb, line 19 def update!(new_version) image = Docker::Image.create('fromImage' => "ruby:#{new_version}") container = Docker::Container.create('Cmd' => 'bundle', 'Image' => "ruby:#{new_version}", 'Env' => env_options) container.store_file("/#{GEMFILE}", File.read("#{git.dir.path}/#{GEMFILE}")) container.store_file("/#{FILENAME}", File.read("#{git.dir.path}/#{FILENAME}")) unless update_gems container.start Rrm.logger.debug "Running 'bundle' inside Docker, please wait. Timeout is #{TIMEOUT_SECONDS} seconds" container.wait(TIMEOUT_SECONDS) new_content = container.read_file("/#{FILENAME}") container.stop file = File.open("#{git.dir.path}/#{FILENAME}", 'w') file.puts new_content file.close git.commit_all(commit_message(new_version)) end
Private Instance Methods
commit_message(new_version)
click to toggle source
# File lib/rrm/filehandlers/gemfile_lock.rb, line 46 def commit_message(new_version) msg = "Updating #{FILENAME} to Ruby #{new_version}" msg << " and updating #{number_of_gem_updates} gems" if update_gems msg end
env_options()
click to toggle source
# File lib/rrm/filehandlers/gemfile_lock.rb, line 37 def env_options arr = [] $env_variables.each do |e| arr << "#{e}=#{ENV[e]}" end Rrm.logger.debug "Passing #{$env_variables} to Docker as Env" arr end
number_of_gem_updates()
click to toggle source
# File lib/rrm/filehandlers/gemfile_lock.rb, line 52 def number_of_gem_updates git.diff.first.patch.split("\n").select{|s| s.start_with?('+')}.select{|s| s.include?("(")}.size rescue "?" end