Class: Rrm::GemfileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/rrm/filehandlers/gemfile_lock.rb

Constant Summary collapse

GEMFILE =
'Gemfile'
FILENAME =
'Gemfile.lock'
TIMEOUT_SECONDS =
240

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git, update_gems) ⇒ GemfileLock

Returns a new instance of GemfileLock.



11
12
13
14
15
16
17
# 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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/rrm/filehandlers/gemfile_lock.rb', line 9

def content
  @content
end

#gitObject

Returns the value of attribute git.



9
10
11
# File 'lib/rrm/filehandlers/gemfile_lock.rb', line 9

def git
  @git
end

#new_versionObject

Returns the value of attribute new_version.



9
10
11
# File 'lib/rrm/filehandlers/gemfile_lock.rb', line 9

def new_version
  @new_version
end

#update_gemsObject

Returns the value of attribute update_gems.



9
10
11
# File 'lib/rrm/filehandlers/gemfile_lock.rb', line 9

def update_gems
  @update_gems
end

Instance Method Details

#update!(new_version) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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