Class: Palimpsest::External
- Inherits:
-
Object
- Object
- Palimpsest::External
- 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
-
#branch ⇒ String
Branch to use for treeish.
-
#install_path ⇒ String
Where the files will be installed to.
-
#name ⇒ String
Repository name.
-
#source ⇒ String
Base source url or path to external git repo (without name).
Instance Method Summary collapse
-
#cleanup ⇒ External
The current external instance.
-
#environment ⇒ Environment
Environment with contents of the repository at the HEAD of the branch.
-
#initialize(name: '', source: '', branch: 'master', install_path: '') ⇒ External
constructor
A new instance of External.
-
#install ⇒ Environment
Copy the files to the #install_path.
- #repo_path ⇒ String
-
#tmp_environment ⇒ Environment
Temporary environment to hold the cloned repository.
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
#branch ⇒ String
Returns branch to use for treeish.
22 |
# File 'lib/palimpsest/external.rb', line 22 attr_accessor :name, :source, :branch, :install_path |
#install_path ⇒ String
Returns where the files will be installed to.
22 |
# File 'lib/palimpsest/external.rb', line 22 attr_accessor :name, :source, :branch, :install_path |
#name ⇒ String
Returns repository name.
22 23 24 |
# File 'lib/palimpsest/external.rb', line 22 def name @name end |
#source ⇒ String
Returns 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
#cleanup ⇒ External
Returns 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 |
#environment ⇒ Environment
Returns 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 |
#install ⇒ Environment
Copy the files to the #install_path.
46 47 48 49 |
# File 'lib/palimpsest/external.rb', line 46 def install environment.populate.copy dest: install_path self end |
#repo_path ⇒ String
32 33 34 |
# File 'lib/palimpsest/external.rb', line 32 def repo_path ( source.empty? || name.empty? ) ? '' : "#{source}/#{name}" end |
#tmp_environment ⇒ Environment
Returns 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 |