class Palimpsest::External

Use this class to manage external repositories you want to include in your project.

Given a name, source and branch, the contents of the repository at the HEAD of the branch will be available as an {Environment} object through {#environment}.

Use {#cleanup} to remove all files created by the {#External} object.

Attributes

branch[RW]

@!attribute name

@return [String] repository name

@!attribute source

@return [String] base source url or path to external git repo (without name)

@!attribute branch

@return [String] branch to use for treeish

@!attribute install_path

@return [String] where the files will be installed to
install_path[RW]

@!attribute name

@return [String] repository name

@!attribute source

@return [String] base source url or path to external git repo (without name)

@!attribute branch

@return [String] branch to use for treeish

@!attribute install_path

@return [String] where the files will be installed to
name[RW]

@!attribute name

@return [String] repository name

@!attribute source

@return [String] base source url or path to external git repo (without name)

@!attribute branch

@return [String] branch to use for treeish

@!attribute install_path

@return [String] where the files will be installed to
source[RW]

@!attribute name

@return [String] repository name

@!attribute source

@return [String] base source url or path to external git repo (without name)

@!attribute branch

@return [String] branch to use for treeish

@!attribute install_path

@return [String] where the files will be installed to

Public Class Methods

new(name: '', source: '', branch: 'master', install_path: '') click to toggle source
# File lib/palimpsest/external.rb, line 24
def initialize name: '', source: '', branch: 'master', install_path: ''
  self.name = name
  self.source = source
  self.branch = branch
  self.install_path = install_path
end

Public Instance Methods

cleanup() click to toggle source

@return [External] the current external instance

# File lib/palimpsest/external.rb, line 52
def cleanup
  environment.cleanup if @environment
  @environment = nil

  tmp_environment.cleanup if @tmp_environment
  @tmp_environment = nil
  self
end
environment() click to toggle source

@return [Environment] environment with contents of the repository at the HEAD of the branch

# File lib/palimpsest/external.rb, line 37
def environment
  return @environment if @environment

  site = Site.new name: "external_#{name.gsub '/', '_'}", repo: Grit::Repo.new(tmp_environment.directory)
  @environment = Environment.new site: site, treeish: branch
end
install() click to toggle source

Copy the files to the {#install_path}. @return (see Environment#copy)

# File lib/palimpsest/external.rb, line 46
def install
  environment.populate.copy dest: install_path
  self
end
repo_path() click to toggle source

@return [String] full path to repo as {#source}‘/`{#name}

# File lib/palimpsest/external.rb, line 32
def repo_path
  ( source.empty? || name.empty? ) ? '' : "#{source}/#{name}"
end
tmp_environment() click to toggle source

@return [Environment] temporary environment to hold the cloned repository

# File lib/palimpsest/external.rb, line 62
def tmp_environment
  return @tmp_environment if @tmp_environment

  fail RuntimeError if repo_path.empty?

  Grit::Git.git_max_size = 200 * 1048576
  Grit::Git.git_timeout = 200

  @tmp_environment = Environment.new site: Site.new(name: "external_clone_#{name.gsub '/', '_'}")
  gritty = Grit::Git.new tmp_environment.directory
  gritty.clone( { branch: branch }, repo_path, tmp_environment.directory )
  @tmp_environment
end