Class: CookbookOmnifetch::PathLocation

Inherits:
BaseLocation show all
Defined in:
lib/cookbook-omnifetch/path.rb

Instance Attribute Summary

Attributes inherited from BaseLocation

#dependency, #options

Instance Method Summary collapse

Methods inherited from BaseLocation

#initialize, #validate_cached!

Constructor Details

This class inherits a constructor from CookbookOmnifetch::BaseLocation

Instance Method Details

#==(other) ⇒ Object



66
67
68
69
70
# File 'lib/cookbook-omnifetch/path.rb', line 66

def ==(other)
  other.is_a?(PathLocation) &&
    other.metadata? == metadata? &&
    other.relative_path == relative_path
end

#cached_cookbookObject



22
23
24
# File 'lib/cookbook-omnifetch/path.rb', line 22

def cached_cookbook
  @cached_cookbook ||= CookbookOmnifetch.cached_cookbook_class.from_path(expanded_path)
end

#expanded_pathPathname

The fully expanded path of this cookbook on disk, relative to the Berksfile.

Returns:

  • (Pathname)


57
58
59
60
61
62
63
64
# File 'lib/cookbook-omnifetch/path.rb', line 57

def expanded_path
  # TODO: this requires Berkshelf::Dependency to provide a delegate (ish) method that does
  #
  # def relative_paths_root
  #   File.dirname(berksfile.filepath)
  # end
  @expanded_path ||= Pathname.new File.expand_path(options[:path], dependency.relative_paths_root)
end

#inspectObject



89
90
91
# File 'lib/cookbook-omnifetch/path.rb', line 89

def inspect
  "#<CookbookOmnifetch::PathLocation metadata: #{metadata?}, path: #{relative_path}>"
end

#installObject

The installation for a path location is actually just a noop



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

def install
  validate_cached!(expanded_path)
end

#install_pathObject



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

def install_path
  relative_path
end

#installed?Boolean

Technically path locations are always installed, but this method intentionally returns false to force validation of the cookbook at the path.

Returns:

  • (Boolean)

See Also:



10
11
12
# File 'lib/cookbook-omnifetch/path.rb', line 10

def installed?
  false
end

#lock_dataObject



72
73
74
75
76
77
# File 'lib/cookbook-omnifetch/path.rb', line 72

def lock_data
  out = {}
  out["path"] = relative_path.to_s
  out["metadata"] = true if metadata?
  out
end

#metadata?Boolean

Returns true if the location is a metadata location. By default, no locations are the metadata location.

Returns:

  • (Boolean)


30
31
32
# File 'lib/cookbook-omnifetch/path.rb', line 30

def metadata?
  !!options[:metadata]
end

#relative_pathPathname

Return this PathLocation’s path relative to the associated Berksfile. It is actually the path reative to the associated Berksfile’s parent directory.

Returns:

  • (Pathname)

    the relative path relative to the target



44
45
46
47
48
49
50
51
# File 'lib/cookbook-omnifetch/path.rb', line 44

def relative_path
  # TODO: this requires Berkshelf::Dependency to provide a delegate (ish) method that does
  #
  # def relative_paths_root
  #   File.dirname(berksfile.filepath)
  # end
  @relative_path ||= expanded_path.relative_path_from(Pathname.new(dependency.relative_paths_root))
end

#to_lockObject



79
80
81
82
83
# File 'lib/cookbook-omnifetch/path.rb', line 79

def to_lock
  out =  "    path: #{relative_path}\n"
  out << "    metadata: true\n" if metadata?
  out
end

#to_sObject



85
86
87
# File 'lib/cookbook-omnifetch/path.rb', line 85

def to_s
  "source at #{relative_path}"
end