Class: Palimpsest::External

Inherits:
Object
  • Object
show all
Defined in:
lib/palimpsest/external.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: '', source: '', branch: 'master', install_path: '') ⇒ External

Returns a new instance of External.



24
25
26
27
28
29
# 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

Instance Attribute Details

#branchString

Returns branch to use for treeish.

Returns:

  • (String)

    branch to use for treeish



22
# File 'lib/palimpsest/external.rb', line 22

attr_accessor :name, :source, :branch, :install_path

#install_pathString

Returns where the files will be installed to.

Returns:

  • (String)

    where the files will be installed to



22
# File 'lib/palimpsest/external.rb', line 22

attr_accessor :name, :source, :branch, :install_path

#nameString

Returns repository name.

Returns:

  • (String)

    repository name



22
23
24
# File 'lib/palimpsest/external.rb', line 22

def name
  @name
end

#sourceString

Returns base source url or path to external git repo (without name).

Returns:

  • (String)

    base source url or path to external git repo (without name)



22
# File 'lib/palimpsest/external.rb', line 22

attr_accessor :name, :source, :branch, :install_path

Instance Method Details

#cleanupExternal

Returns the current external instance.

Returns:

  • (External)

    the current external instance



52
53
54
55
56
57
58
59
# 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

#environmentEnvironment

Returns environment with contents of the repository at the HEAD of the branch.

Returns:

  • (Environment)

    environment with contents of the repository at the HEAD of the branch



37
38
39
40
41
42
# 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

#installEnvironment

Copy the files to the #install_path.

Returns:



46
47
48
49
# File 'lib/palimpsest/external.rb', line 46

def install
  environment.populate.copy dest: install_path
  self
end

#repo_pathString

Returns full path to repo as #source/#name.

Returns:



32
33
34
# File 'lib/palimpsest/external.rb', line 32

def repo_path
  ( source.empty? || name.empty? ) ? '' : "#{source}/#{name}"
end

#tmp_environmentEnvironment

Returns temporary environment to hold the cloned repository.

Returns:

  • (Environment)

    temporary environment to hold the cloned repository



62
63
64
65
66
67
68
69
70
71
72
73
74
# 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