Class: Berkshelf::PathLocation
- Inherits:
-
Object
- Object
- Berkshelf::PathLocation
- Includes:
- Location
- Defined in:
- lib/berkshelf/locations/path_location.rb
Overview
Constant Summary
Constants included from Location
Location::OPSCODE_COMMUNITY_API
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Attributes included from Location
Class Method Summary collapse
-
.normalize_path(path) ⇒ String
Expand and return a string representation of the given path if it is absolute or a path in the users home directory.
Instance Method Summary collapse
- #download(destination) ⇒ Berkshelf::CachedCookbook
-
#initialize(name, version_constraint, options = {}) ⇒ PathLocation
constructor
A new instance of PathLocation.
- #to_hash ⇒ Object
- #to_s ⇒ Object
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.
36 37 38 39 40 41 |
# File 'lib/berkshelf/locations/path_location.rb', line 36 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @path = [:path] set_downloaded_status(true) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/berkshelf/locations/path_location.rb', line 28 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
27 28 29 |
# File 'lib/berkshelf/locations/path_location.rb', line 27 def path @path end |
Class Method Details
.normalize_path(path) ⇒ String
Expand and return a string representation of the given path if it is absolute or a path in the users home directory.
Returns the given relative path otherwise.
13 14 15 16 17 18 19 20 |
# File 'lib/berkshelf/locations/path_location.rb', line 13 def normalize_path(path) path = path.to_s if (path[0] == "~") || Pathname.new(path).absolute? File.(path) else path end end |
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
46 47 48 49 50 51 52 53 54 |
# File 'lib/berkshelf/locations/path_location.rb', line 46 def download(destination) cached = CachedCookbook.from_path(path, name: name) validate_cached(cached) set_downloaded_status(true) cached rescue IOError raise Berkshelf::CookbookNotFound end |
#to_hash ⇒ Object
56 57 58 |
# File 'lib/berkshelf/locations/path_location.rb', line 56 def to_hash super.merge(value: self.path) end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/berkshelf/locations/path_location.rb', line 60 def to_s "#{self.class.location_key}: '#{path}'" end |