Module: Satorix::CI::Shared::Ruby::GemManager

Extended by:
GemManager
Includes:
Shared::Console
Included in:
GemManager
Defined in:
lib/satorix/CI/shared/ruby/gem_manager.rb

Instance Method Summary collapse

Methods included from Shared::Console

#colorize, #colors, #humanize_time, #log, #log_bench, #log_command, #log_duration, #log_error, #log_error_and_abort, #log_header, #run_command, #source_env_from

Instance Method Details

#go(quiet = true) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 12

def go(quiet = true)
  if Satorix.ci_job_stage == 'deploy'
    prepare_gem_for_deployment(quiet)
  else
    prepare_gem_environment_for_test(quiet)
  end
end

#prepare_gem_environment_for_test(quiet = true) ⇒ Object



31
32
33
34
35
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 31

def prepare_gem_environment_for_test(quiet = true)
  log_bench 'Preparing gem environment...' do
    restore_missing_gems(quiet)
  end
end

#prepare_gem_for_deployment(quiet = true) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 21

def prepare_gem_for_deployment(quiet = true)
  log_bench 'Preparing gem for deployment...' do
    # Development dependencies should not be included in the Gemfile.lock
    # otherwise they will become dependencies of the implementing application
    remove_development_dependencies_from_gemspec(quiet)
    regenerate_gemfile_lock(quiet)
  end
end

#regenerate_gemfile_lock(quiet = true) ⇒ Object



66
67
68
69
70
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 66

def regenerate_gemfile_lock(quiet = true)
  run_command(%w[bundle config --local frozen false], quiet: quiet)
  run_command(%w[bundle install], quiet: quiet)
  log "\n\n#{ File.read(File.join(Satorix.app_dir, 'Gemfile.lock')) }" unless quiet
end

#remove_development_dependencies_from_gemspec(quiet = true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 45

def remove_development_dependencies_from_gemspec(quiet = true)
  Dir[File.join(Satorix.app_dir, '*.gemspec')].each do |file|
    log File.read(file) unless quiet

    backup_file_name = "#{ file }.satorix.old"
    FileUtils.mv(file, backup_file_name)

    File.open(file, 'w') do |modified_file|
      File.foreach(backup_file_name) do |line|
        modified_file.puts line unless line =~ /\.add_development_dependency/
      end
    end

    File.delete(backup_file_name)

    log File.read(file) unless quiet
  end

end

#restore_missing_gems(quiet = true) ⇒ Object



38
39
40
41
42
# File 'lib/satorix/CI/shared/ruby/gem_manager.rb', line 38

def restore_missing_gems(quiet = true)
  # The buildpack incorrectly removes gems that are included using add_development_dependency.
  # These gems must remain available for testing.
  run_command(%w[bundle install --with development], quiet: quiet)
end