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.
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#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.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/berkshelf/locations/git_location.rb', line 43 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @uri = [:git] @branch = [:branch] || [:ref] || [:tag] || "master" @rel = [:rel] @branch_name = @branch.gsub("-", "_").gsub("/", "__") # In case the remote is specified 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 |
#branch_name ⇒ Object
Returns the value of attribute branch_name.
23 24 25 |
# File 'lib/berkshelf/locations/git_location.rb', line 23 def branch_name @branch_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/berkshelf/locations/git_location.rb', line 24 def @options 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
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 82 83 84 |
# File 'lib/berkshelf/locations/git_location.rb', line 57 def download(destination) return local_revision(destination) if cached?(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 puts "File.chef_cookbook?(tmp_path): #{File.chef_cookbook?(tmp_path)}" 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, "#{name}-#{branch_name}") 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) puts "cached.class: #{cached.class}" cached end |
#to_hash ⇒ Object
86 87 88 89 90 91 |
# File 'lib/berkshelf/locations/git_location.rb', line 86 def to_hash super.tap do |h| h[:value] = self.uri h[:branch] = self.branch if branch end end |
#to_s ⇒ Object
93 94 95 96 97 |
# File 'lib/berkshelf/locations/git_location.rb', line 93 def to_s s = "#{self.class.location_key}: '#{uri}'" s << " with branch: '#{branch}'" if branch s end |