Class: CookbookOmnifetch::BaseLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook-omnifetch/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BaseLocation.



8
9
10
11
# File 'lib/cookbook-omnifetch/base.rb', line 8

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

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



5
6
7
# File 'lib/cookbook-omnifetch/base.rb', line 5

def dependency
  @dependency
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/cookbook-omnifetch/base.rb', line 6

def options
  @options
end

Instance Method Details

#cached_cookbookCachedCookbook

The cached cookbook for this location.

Returns:

  • (CachedCookbook)

Raises:



33
34
35
36
# File 'lib/cookbook-omnifetch/base.rb', line 33

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:



25
26
27
28
# File 'lib/cookbook-omnifetch/base.rb', line 25

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

#installed?Boolean

Determine if this revision is installed.

Returns:

  • (Boolean)

Raises:



16
17
18
19
# File 'lib/cookbook-omnifetch/base.rb', line 16

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

#lock_dataHash

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

Returns:

  • (Hash)

Raises:



41
42
43
44
# File 'lib/cookbook-omnifetch/base.rb', line 41

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

#to_lockstring

The lockfile representation of this location.

Returns:

  • (string)

Raises:



49
50
51
52
# 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) ⇒ 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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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