Sha256: 5590142c6c13751fd7cc95a40bdbe8e7f0078083a39e8a52511e004697c5fff0

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

module Berkshelf
  # @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
    attr_reader :name

    # @param [#to_s] name
    # @param [Solve::Constraint] version_constraint
    # @param [Hash] options
    #
    # @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               = options[:path]
      set_downloaded_status(true)
    end

    # @param [#to_s] destination
    #
    # @return [Berkshelf::CachedCookbook]
    def download(destination)
      cached = CachedCookbook.from_path(path, name: name)
      validate_cached(cached)

      set_downloaded_status(true)
      cached
    rescue IOError
      raise Berkshelf::CookbookNotFound
    end

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
berkshelf-1.4.6 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.5 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.4 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.3 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.2 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.1 lib/berkshelf/locations/path_location.rb
berkshelf-1.4.0 lib/berkshelf/locations/path_location.rb