module Cutlass

Cutlass

Constants

VERSION

Version

Attributes

default_builder[RW]

Public Class Methods

config() { |self| ... } click to toggle source
# File lib/cutlass.rb, line 17
def self.config
  yield self
end
debug?() click to toggle source
# File lib/cutlass.rb, line 66
def self.debug?
  ENV["CUTLASS_DEBUG"] || ENV["DEBUG"]
end
default_buildpack_paths() click to toggle source
# File lib/cutlass.rb, line 32
def self.default_buildpack_paths
  raise "Must set Cutlass.default_buildpack_paths to a non-empty value" if @default_buildpack_paths.empty? || @default_buildpack_paths.nil?

  @default_buildpack_paths
end
default_buildpack_paths=(paths) click to toggle source
# File lib/cutlass.rb, line 26
def self.default_buildpack_paths=(paths)
  paths = Array(paths).map { |path| path.respond_to?(:exist?) ? path : Pathname(path) }

  @default_buildpack_paths = paths
end
default_image_name() click to toggle source
# File lib/cutlass.rb, line 70
def self.default_image_name
  "cutlass_image_#{SecureRandom.hex(10)}"
end
default_repo_dirs() click to toggle source
# File lib/cutlass.rb, line 44
def self.default_repo_dirs
  @default_repo_dirs
end
default_repo_dirs=(dirs) click to toggle source
# File lib/cutlass.rb, line 40
def self.default_repo_dirs=(dirs)
  @default_repo_dirs = Array(dirs).map { |dir| Pathname(dir) }
end
in_fork() { || ... } click to toggle source

Runs the block in a process fork to isolate memory or environment changes such as ENV var modifications

# File lib/cutlass.rb, line 76
def self.in_fork
  Tempfile.create("stdout") do |tmp_file|
    pid = fork do
      $stdout.reopen(tmp_file, "a")
      $stderr.reopen(tmp_file, "a")
      $stdout.sync = true
      $stderr.sync = true
      yield
      Kernel.exit!(0) # needed for https://github.com/seattlerb/minitest/pull/683
    end
    Process.waitpid(pid)

    if $?.success?
      print File.read(tmp_file)
    else
      raise File.read(tmp_file)
    end
  end
end
resolve_path(path) click to toggle source

Given a full path that exists it will return the same path. Given the name of a directory within the default repo dirs, it will match and return a full path

# File lib/cutlass.rb, line 51
  def self.resolve_path(path)
    return Pathname(path) if Dir.exist?(path)

    children = @default_repo_dirs.map(&:children).flatten
    resolved = children.detect { |p| p.basename.to_s == path }

    return resolved if resolved

    raise(<<~EOM)
      No such directory name: #{path.inspect}

      #{children.map(&:basename).join($/)}
    EOM
  end