lib/berkshelf/locations/path_location.rb in berkshelf-1.1.6 vs lib/berkshelf/locations/path_location.rb in berkshelf-1.2.0.rc1
- old
+ new
@@ -1,8 +1,27 @@
module Berkshelf
- # @author Jamie Winsor <jamie@vialstudios.com>
+ # @author Jamie Winsor <reset@riotgames.com>
class PathLocation
+ class << self
+ # 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.
+ #
+ # @param [#to_s] path
+ #
+ # @return [String]
+ def normalize_path(path)
+ path = path.to_s
+ if (path[0] == "~") || Pathname.new(path).absolute?
+ File.expand_path(path)
+ else
+ path
+ end
+ end
+ end
+
include Location
set_location_key :path
attr_accessor :path
@@ -14,18 +33,18 @@
# @option options [String] :path
# a filepath to the cookbook on your local disk
def initialize(name, version_constraint, options = {})
@name = name
@version_constraint = version_constraint
- @path = File.expand_path(options[:path])
+ @path = self.class.normalize_path(options[:path])
set_downloaded_status(true)
end
# @param [#to_s] destination
#
# @return [Berkshelf::CachedCookbook]
def download(destination)
- cached = CachedCookbook.from_path(path)
+ cached = CachedCookbook.from_path(File.expand_path(path))
validate_cached(cached)
set_downloaded_status(true)
cached
end