Class: Berkshelf::BzrLocation
- Inherits:
-
BaseLocation
- Object
- BaseLocation
- Berkshelf::BzrLocation
- Defined in:
- lib/berkshelf/locations/bzr.rb
Defined Under Namespace
Classes: BzrCommandError, BzrError, BzrNotInstalled
Instance Attribute Summary collapse
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cached_cookbook ⇒ Object
-
#initialize(dependency, options = {}) ⇒ BzrLocation
constructor
A new instance of BzrLocation.
-
#install ⇒ Object
Install this bzr cookbook into the cookbook store.
-
#installed? ⇒ Boolean
Determine if this revision is installed.
- #to_lock ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dependency, options = {}) ⇒ BzrLocation
Returns a new instance of BzrLocation.
35 36 37 38 39 40 41 |
# File 'lib/berkshelf/locations/bzr.rb', line 35 def initialize(dependency, = {}) super @uri = [:bzr] @revision = [:revision] @ref = [:ref] || 'last:' end |
Instance Attribute Details
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
33 34 35 |
# File 'lib/berkshelf/locations/bzr.rb', line 33 def ref @ref end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
32 33 34 |
# File 'lib/berkshelf/locations/bzr.rb', line 32 def revision @revision end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
31 32 33 |
# File 'lib/berkshelf/locations/bzr.rb', line 31 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
88 89 90 91 92 |
# File 'lib/berkshelf/locations/bzr.rb', line 88 def ==(other) other.is_a?(BzrLocation) && other.uri == uri && other.ref == ref end |
#cached_cookbook ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/berkshelf/locations/bzr.rb', line 80 def cached_cookbook if installed? @cached_cookbook ||= CachedCookbook.from_path(install_path) else nil end end |
#install ⇒ Object
Install this bzr cookbook into the cookbook store. This method leverages a cached bzr copy and a scratch directory to prevent bad cookbooks from making their way into the cookbook store.
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/bzr.rb', line 55 def install if cached? && valid? Dir.chdir(cache_path) do bzr %|pull| end else FileUtils.mkdir_p(cache_path.dirname) bzr %|branch #{uri} #{cache_path}| end Dir.chdir(cache_path) do bzr %|update -r #{@revision || @ref}| end @revision ||= revid(cache_path) # Validate the scratched path is a valid cookbook validate_cached!(cache_path) # If we got this far, we should copy FileUtils.rm_rf(install_path) if install_path.exist? FileUtils.cp_r(cache_path, install_path) install_path.chmod(0777 & ~File.umask) end |
#installed? ⇒ Boolean
Determine if this revision is installed.
46 47 48 |
# File 'lib/berkshelf/locations/bzr.rb', line 46 def installed? revision && install_path.exist? end |
#to_lock ⇒ Object
98 99 100 101 102 103 |
# File 'lib/berkshelf/locations/bzr.rb', line 98 def to_lock out = " bzr: #{uri}\n" out << " revision: #{revision}\n" out << " ref: #{ref}\n" if ref out end |
#to_s ⇒ Object
94 95 96 |
# File 'lib/berkshelf/locations/bzr.rb', line 94 def to_s "#{uri} (at ref: #{ref})" end |