class CookbookOmnifetch::BaseLocation

Attributes

dependency[R]
options[R]

Public Class Methods

new(dependency, options = {}) click to toggle source
# File lib/cookbook-omnifetch/base.rb, line 8
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/cookbook-omnifetch/base.rb, line 33
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/cookbook-omnifetch/base.rb, line 25
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/cookbook-omnifetch/base.rb, line 16
def installed?
  raise AbstractFunction,
    "#installed? must be implemented on #{self.class.name}!"
end
lock_data() click to toggle source

A representation of this location suitable for a lockfile, given as a Hash

@return [Hash]

# File lib/cookbook-omnifetch/base.rb, line 41
def lock_data
  raise AbstractFunction,
    "#to_lock must be implemented on #{self.class.name}!"
end
to_lock() click to toggle source

The lockfile representation of this location.

@return [string]

# File lib/cookbook-omnifetch/base.rb, line 49
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/cookbook-omnifetch/base.rb, line 67
def validate_cached!(path)
  unless CookbookOmnifetch.cookbook?(path)
    raise NotACookbook.new(path)
  end

  cookbook = CookbookOmnifetch.cached_cookbook_class.from_path(path)

  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