lib/berkshelf/locations/path_location.rb in berkshelf-2.0.18 vs lib/berkshelf/locations/path_location.rb in berkshelf-3.0.0.beta1
- old
+ new
@@ -1,7 +1,7 @@
module Berkshelf
- class PathLocation
+ class PathLocation < Location::Base
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.
@@ -17,39 +17,31 @@
path
end
end
end
- include Location
-
set_location_key :path
set_valid_options :path, :metadata
attr_accessor :path
- attr_reader :name
- # @param [#to_s] name
+ # @param [#to_s] dependency
# @param [Solve::Constraint] version_constraint
# @param [Hash] options
#
# @option options [#to_s] :path
# a filepath to the cookbook on your local disk
# @option options [Boolean] :metadata
# true if this is a metadata source
- def initialize(name, version_constraint, options = {})
- @name = name
- @version_constraint = version_constraint
- @path = options[:path].to_s
- @metadata = options[:metadata]
+ def initialize(dependency, options = {})
+ super
+ @path = options[:path].to_s
+ @metadata = options[:metadata]
end
- # The cookbook associated with this path location.
- #
- # @return [Berkshelf::CachedCookbook]
- # the cached cookbook for this location
- def cookbook
- @cookbook ||= CachedCookbook.from_path(path, name: name)
+ def do_download
+ CachedCookbook.from_path(path, name: name)
end
# Returns true if the location is a metadata location. By default, no
# locations are the metadata location.
#
@@ -78,25 +70,16 @@
def to_hash
super.merge(value: self.path)
end
- # The string representation of this PathLocation. If the path
- # is the default cookbook store, just leave it out, because
- # it's probably just cached.
+ # The string representation of this PathLocation
#
# @example
- # loc.to_s #=> artifact (1.4.0)
- #
- # @example
# loc.to_s #=> artifact (1.4.0) at path: '/Users/Seth/Dev/artifact'
#
# @return [String]
def to_s
- if path.to_s.include?(Berkshelf.berkshelf_path.to_s)
- "#{self.class.location_key}"
- else
- "#{self.class.location_key}: '#{path}'"
- end
+ "#{self.class.location_key}: '#{File.expand_path(path)}'"
end
end
end