class Lono::Jade::Materializer::GemsBuilder

Public Class Methods

new(*jades) click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 7
def initialize(*jades)
  @jades = jades.flatten
  @build_root = "#{Lono.root}/tmp/jades"
end

Public Instance Methods

build() click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 12
def build
  puts "GemsBuilder#build materializing #{@jades.map(&:name)}" if ENV['LONO_DEBUG']
  remove_gemfile
  gemfile = build_gemfile(@jades)
  return unless gemfile
  write(gemfile)
  bundle
end
build_gemfile(jades) click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 21
def build_gemfile(jades)
  return if jades.empty?

  lines = []
  jades.each do |jade|
    return if local_exist?(jade)
    args = source.gem_args(jade)
    line = %Q|gem #{args}|
    lines << line unless lines.include?(line)
  end
  lines.sort!
  lines.join("\n") + "\n"
end
bundle() click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 35
def bundle
  Bundler.with_unbundled_env do
    bundle_install
  end
end
bundle_install() click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 41
def bundle_install
  command = "cd #{@build_root} && bundle install"
  puts "=> #{command}" if ENV['LONO_DEBUG']
  stdout, stderr, status = Open3.capture3(command)

  unless status.success?
    names = @jades.map(&:name)
    gem_text = names.size == 1 ? "gem" : "gems"
    puts "Fail to build #{gem_text} #{names.join(', ')}".color(:red)
    puts "Failed running => #{command}"
    puts stdout
    puts stderr
    if stderr.include?("correct access rights")
      puts "Are you sure you have access to the git repo and the repo exists?".color(:yellow)
    end
    exit 1
  end
end
local_exist?(jade) click to toggle source

When a local version is found, will use that version

# File lib/lono/jade/materializer/gems_builder.rb, line 61
def local_exist?(jade)
  !!jade.finder.find(jade.name, local_only: true)
end
remove_gemfile() click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 71
def remove_gemfile
  FileUtils.rm_f("#{@build_root}/Gemfile")
  FileUtils.rm_f("#{@build_root}/Gemfile.lock")
end
source() click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 76
def source
  Source.new
end
write(gemfile) click to toggle source
# File lib/lono/jade/materializer/gems_builder.rb, line 65
def write(gemfile)
  path = "#{@build_root}/Gemfile"
  FileUtils.mkdir_p(File.dirname(path))
  IO.write(path, gemfile)
end