Class: Berkshelf::GitLocation
- Inherits:
-
Object
- Object
- Berkshelf::GitLocation
- Includes:
- Location
- Defined in:
- lib/berkshelf/locations/git_location.rb
Overview
Direct Known Subclasses
Constant Summary
Constants included from Location
Location::OPSCODE_COMMUNITY_API
Instance Attribute Summary collapse
-
#branch ⇒ Object
(also: #ref, #tag)
Returns the value of attribute branch.
-
#rel ⇒ Object
Returns the value of attribute rel.
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes included from Location
Class Method Summary collapse
-
.tmpdir ⇒ String
Create a temporary directory for the cloned repository within Berkshelf’s temporary directory.
Instance Method Summary collapse
- #download(destination) ⇒ Berkshelf::CachedCookbook
-
#initialize(name, version_constraint, options = {}) ⇒ GitLocation
constructor
A new instance of GitLocation.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Location
#downloaded?, included, init, #to_json, #validate_cached
Constructor Details
#initialize(name, version_constraint, options = {}) ⇒ GitLocation
Returns a new instance of GitLocation.
41 42 43 44 45 46 47 48 49 |
# File 'lib/berkshelf/locations/git_location.rb', line 41 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @uri = [:git] @branch = [:branch] || [:ref] || [:tag] @rel = [:rel] Git.validate_uri!(@uri) end |
Instance Attribute Details
#branch ⇒ Object Also known as: ref, tag
Returns the value of attribute branch.
21 22 23 |
# File 'lib/berkshelf/locations/git_location.rb', line 21 def branch @branch end |
#rel ⇒ Object
Returns the value of attribute rel.
22 23 24 |
# File 'lib/berkshelf/locations/git_location.rb', line 22 def rel @rel end |
#uri ⇒ Object
Returns the value of attribute uri.
20 21 22 |
# File 'lib/berkshelf/locations/git_location.rb', line 20 def uri @uri end |
Class Method Details
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/berkshelf/locations/git_location.rb', line 54 def download(destination) ::Berkshelf::Git.checkout(clone, branch) if branch unless branch self.branch = ::Berkshelf::Git.rev_parse(clone) end tmp_path = rel ? File.join(clone, rel) : clone unless File.chef_cookbook?(tmp_path) msg = "Cookbook '#{name}' not found at git: #{uri}" msg << " with branch '#{branch}'" if branch msg << " at path '#{rel}'" if rel raise CookbookNotFound, msg end cb_path = File.join(destination, "#{self.name}-#{Git.rev_parse(clone)}") FileUtils.rm_rf(cb_path) FileUtils.mv(tmp_path, cb_path) cached = CachedCookbook.from_store_path(cb_path) validate_cached(cached) set_downloaded_status(true) cached end |
#to_hash ⇒ Object
79 80 81 82 83 84 |
# File 'lib/berkshelf/locations/git_location.rb', line 79 def to_hash super.tap do |h| h[:value] = self.uri h[:branch] = self.branch if branch end end |
#to_s ⇒ Object
86 87 88 89 90 |
# File 'lib/berkshelf/locations/git_location.rb', line 86 def to_s s = "#{self.class.location_key}: '#{uri}'" s << " with branch: '#{branch}'" if branch s end |