Class: Berkshelf::GitLocation
- Inherits:
-
Object
- Object
- Berkshelf::GitLocation
- Includes:
- Location
- Defined in:
- lib/berkshelf/locations/git_location.rb
Direct Known Subclasses
Constant Summary
Constants included from Location
Location::OPSCODE_COMMUNITY_API
Instance Attribute Summary collapse
-
#branch ⇒ Object
(also: #tag)
Returns the value of attribute branch.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#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
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 50 |
# File 'lib/berkshelf/locations/git_location.rb', line 41 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @uri = [:git] @branch = [:branch] || [:tag] || 'master' @ref = [:ref] @rel = [:rel] Git.validate_uri!(@uri) end |
Instance Attribute Details
#branch ⇒ Object Also known as: tag
Returns the value of attribute branch.
20 21 22 |
# File 'lib/berkshelf/locations/git_location.rb', line 20 def branch @branch end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/berkshelf/locations/git_location.rb', line 23 def @options end |
#ref ⇒ Object
Returns the value of attribute ref.
22 23 24 |
# File 'lib/berkshelf/locations/git_location.rb', line 22 def ref @ref end |
#rel ⇒ Object
Returns the value of attribute rel.
21 22 23 |
# File 'lib/berkshelf/locations/git_location.rb', line 21 def rel @rel end |
#uri ⇒ Object
Returns the value of attribute uri.
19 20 21 |
# File 'lib/berkshelf/locations/git_location.rb', line 19 def uri @uri end |
Class Method Details
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/berkshelf/locations/git_location.rb', line 55 def download(destination) if cached?(destination) @ref ||= Berkshelf::Git.rev_parse(revision_path(destination)) return local_revision(destination) end Berkshelf::Git.checkout(clone, ref || branch) if ref || branch @ref = Berkshelf::Git.rev_parse(clone) 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 << " with ref '#{ref}'" if ref msg << " at path '#{rel}'" if rel raise CookbookNotFound, msg end cb_path = File.join(destination, "#{name}-#{ref}") FileUtils.rm_rf(cb_path) FileUtils.mv(tmp_path, cb_path) cached = CachedCookbook.from_store_path(cb_path) validate_cached(cached) cached end |
#to_hash ⇒ Object
83 84 85 86 87 88 |
# File 'lib/berkshelf/locations/git_location.rb', line 83 def to_hash super.tap do |h| h[:value] = self.uri h[:branch] = self.branch if branch end end |
#to_s ⇒ Object
90 91 92 93 94 95 |
# File 'lib/berkshelf/locations/git_location.rb', line 90 def to_s s = "#{self.class.location_key}: '#{uri}'" s << " with branch: '#{branch}'" if branch s << " at ref: '#{ref}'" if ref s end |