Class: Berkshelf::BaseLocation

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

Direct Known Subclasses

GitLocation, PathLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency, options = {}) ⇒ BaseLocation

Returns a new instance of BaseLocation.



6
7
8
9
# File 'lib/berkshelf/locations/base.rb', line 6

def initialize(dependency, options = {})
  @dependency = dependency
  @options    = options
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



3
4
5
# File 'lib/berkshelf/locations/base.rb', line 3

def dependency
  @dependency
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/berkshelf/locations/base.rb', line 4

def options
  @options
end

Instance Method Details

#cached_cookbookCachedCookbook

The cached cookbook for this location.

Returns:

Raises:



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

def cached_cookbook
  raise AbstractFunction,
    "#cached_cookbook must be implemented on #{self.class.name}!"
end

#installvoid

This method returns an undefined value.

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

Raises:



23
24
25
26
# File 'lib/berkshelf/locations/base.rb', line 23

def install
  raise AbstractFunction,
    "#install must be implemented on #{self.class.name}!"
end

#installed?Boolean

Determine if this revision is installed.

Returns:

  • (Boolean)

Raises:



14
15
16
17
# File 'lib/berkshelf/locations/base.rb', line 14

def installed?
  raise AbstractFunction,
    "#installed? must be implemented on #{self.class.name}!"
end

#to_lockstring

The lockfile representation of this location.

Returns:

  • (string)

Raises:



39
40
41
42
# 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) ⇒ true

Ensure the given CachedCookbook is valid

Parameters:

  • path (String)

    the path to the possible cookbook

Returns:

  • (true)

Raises:

  • (NotACookbook)

    if the cookbook at the path does not have a metadata

  • (CookbookValidationFailure)

    if given CachedCookbook does not satisfy the constraint of the location

  • (MismatcheCookboookName)

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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