class Berkshelf::BaseLocation

Attributes

dependency[R]
options[R]

Public Class Methods

new(dependency, options = {}) click to toggle source
# File lib/berkshelf/locations/base.rb, line 6
def initialize(dependency, options = {})
  @dependency = dependency
  @options    = options
end

Public Instance Methods

cached_cookbook() click to toggle source

The cached cookbook for this location.

@return [CachedCookbook]

# File lib/berkshelf/locations/base.rb, line 31
def cached_cookbook
  raise AbstractFunction,
    "#cached_cookbook must be implemented on #{self.class.name}!"
end
install() click to toggle source

Install the given cookbook. Subclasses that implement this method should perform all the installation and validation steps required.

@return [void]

# File lib/berkshelf/locations/base.rb, line 23
def install
  raise AbstractFunction,
    "#install must be implemented on #{self.class.name}!"
end
installed?() click to toggle source

Determine if this revision is installed.

@return [Boolean]

# File lib/berkshelf/locations/base.rb, line 14
def installed?
  raise AbstractFunction,
    "#installed? must be implemented on #{self.class.name}!"
end
to_lock() click to toggle source

The lockfile representation of this location.

@return [string]

# File lib/berkshelf/locations/base.rb, line 39
def to_lock
  raise AbstractFunction,
    "#to_lock must be implemented on #{self.class.name}!"
end
validate_cached!(path) click to toggle source

Ensure the given {CachedCookbook} is valid

@param [String] path

the path to the possible cookbook

@raise [NotACookbook]

if the cookbook at the path does not have a metadata

@raise [CookbookValidationFailure]

if given CachedCookbook does not satisfy the constraint of the location

@raise [MismatcheCookboookName]

if the cookbook does not have a name or if the name is different

@return [true]

# File lib/berkshelf/locations/base.rb, line 57
def validate_cached!(path)
  unless File.cookbook?(path)
    raise NotACookbook.new(path)
  end

  begin
    cookbook = CachedCookbook.from_path(path)
  rescue => e
    raise InternalError, "The following error occurred while reading the " \
      "cookbook `#{dependency.name}':\n#{e.class}: #{e.message}"
  end

  unless @dependency.version_constraint.satisfies?(cookbook.version)
    raise CookbookValidationFailure.new(dependency, cookbook)
  end

  unless @dependency.name == cookbook.cookbook_name
    raise MismatchedCookbookName.new(dependency, cookbook)
  end

  true
end