Class: Berkshelf::BzrLocation

Inherits:
BaseLocation
  • Object
show all
Defined in:
lib/berkshelf/locations/bzr.rb

Defined Under Namespace

Classes: BzrCommandError, BzrError, BzrNotInstalled

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  super

  @uri      = options[:bzr]
  @revision    = options[:revision]
  @ref      = options[:ref] || 'last:'
end

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref.



33
34
35
# File 'lib/berkshelf/locations/bzr.rb', line 33

def ref
  @ref
end

#revisionObject (readonly)

Returns the value of attribute revision.



32
33
34
# File 'lib/berkshelf/locations/bzr.rb', line 32

def revision
  @revision
end

#uriObject (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_cookbookObject

See Also:

  • BaseLocation#cached_cookbook


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

#installObject

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.

See Also:

  • BaseLocation#install


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.

Returns:

  • (Boolean)


46
47
48
# File 'lib/berkshelf/locations/bzr.rb', line 46

def installed?
  revision && install_path.exist?
end

#to_lockObject



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_sObject



94
95
96
# File 'lib/berkshelf/locations/bzr.rb', line 94

def to_s
  "#{uri} (at ref: #{ref})"
end