Class: Berkshelf::PathLocation
- Inherits:
-
Object
- Object
- Berkshelf::PathLocation
- Includes:
- Location
- Defined in:
- lib/berkshelf/locations/path_location.rb
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
-
#cookbook ⇒ Berkshelf::CachedCookbook
The cookbook associated with this path location.
-
#initialize(name, version_constraint, options = {}) ⇒ PathLocation
constructor
A new instance of PathLocation.
-
#metadata? ⇒ Boolean
Returns true if the location is a metadata location.
-
#relative_path(target = '.') ⇒ String
Return this PathLocation’s path relative to the given target.
- #to_hash ⇒ Object
-
#to_s ⇒ String
The string representation of this PathLocation.
Methods included from Location
#download, included, init, #to_json, #validate_cached
Constructor Details
#initialize(name, version_constraint, options = {}) ⇒ PathLocation
Returns a new instance of PathLocation.
38 39 40 41 42 43 |
# File 'lib/berkshelf/locations/path_location.rb', line 38 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @path = [:path].to_s @metadata = [:metadata] 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.
12 13 14 15 16 17 18 19 |
# File 'lib/berkshelf/locations/path_location.rb', line 12 def normalize_path(path) path = path.to_s if (path[0] == '~') || Pathname.new(path).absolute? File.(path) else path end end |
Instance Method Details
#cookbook ⇒ Berkshelf::CachedCookbook
The cookbook associated with this path location.
49 50 51 |
# File 'lib/berkshelf/locations/path_location.rb', line 49 def cookbook @cookbook ||= CachedCookbook.from_path(path, name: name) end |
#metadata? ⇒ Boolean
Returns true if the location is a metadata location. By default, no locations are the metadata location.
57 58 59 |
# File 'lib/berkshelf/locations/path_location.rb', line 57 def !!@metadata end |
#relative_path(target = '.') ⇒ String
Return this PathLocation’s path relative to the given target.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/berkshelf/locations/path_location.rb', line 68 def relative_path(target = '.') my_path = Pathname.new(path). target_path = Pathname.new(target.to_s). target_path = target_path.dirname if target_path.file? new_path = my_path.relative_path_from(target_path).to_s return new_path if new_path.index('.') == 0 "./#{new_path}" end |
#to_hash ⇒ Object
79 80 81 |
# File 'lib/berkshelf/locations/path_location.rb', line 79 def to_hash super.merge(value: self.path) end |
#to_s ⇒ String
The string representation of this PathLocation. If the path is the default cookbook store, just leave it out, because it’s probably just cached.
94 95 96 97 98 99 100 |
# File 'lib/berkshelf/locations/path_location.rb', line 94 def to_s if path.to_s.include?(Berkshelf.berkshelf_path.to_s) "#{self.class.location_key}" else "#{self.class.location_key}: '#{path}'" end end |