Class: Berkshelf::PathLocation

Inherits:
Object
  • Object
show all
Includes:
Location
Defined in:
lib/berkshelf/locations/path_location.rb

Overview

Author:

Constant Summary

Constants included from Location

Location::OPSCODE_COMMUNITY_API

Instance Attribute Summary collapse

Attributes included from Location

#name, #version_constraint

Instance Method Summary collapse

Methods included from Location

#downloaded?, included, init, #to_json, #validate_cached

Constructor Details

#initialize(name, version_constraint, options = {}) ⇒ PathLocation

Returns a new instance of PathLocation.

Parameters:

  • name (#to_s)
  • version_constraint (Solve::Constraint)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path (String)

    a filepath to the cookbook on your local disk



16
17
18
19
20
21
# File 'lib/berkshelf/locations/path_location.rb', line 16

def initialize(name, version_constraint, options = {})
  @name               = name
  @version_constraint = version_constraint
  @path               = File.expand_path(options[:path])
  set_downloaded_status(true)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/berkshelf/locations/path_location.rb', line 8

def path
  @path
end

Instance Method Details

#download(destination) ⇒ Berkshelf::CachedCookbook

Parameters:

  • destination (#to_s)

Returns:



26
27
28
29
30
31
32
# File 'lib/berkshelf/locations/path_location.rb', line 26

def download(destination)
  cached = CachedCookbook.from_path(path)
  validate_cached(cached)

  set_downloaded_status(true)
  cached
end

#to_hashObject



34
35
36
# File 'lib/berkshelf/locations/path_location.rb', line 34

def to_hash
  super.merge(value: self.path)
end

#to_sObject



38
39
40
# File 'lib/berkshelf/locations/path_location.rb', line 38

def to_s
  "#{self.class.location_key}: '#{path}'"
end