Sha256: da15d3572276daece658da16289875e4778eb3098ac42e52273d6ac103f1df45

Contents?: true

Size: 759 Bytes

Versions: 2

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true

module Deadpull
  module Values
    class LocalLocation < Base
      extend Dry::Initializer

      param(:path, proc { |path| path.is_a?(Pathname) ? path : Pathname.new(File.expand_path(path)) })
      param :prefix
      param :key

      def concretize
        create_local_directory unless local_directory_exists?
        local_path
      end

      private

      def local_path
        @local_path ||= path.join(key.sub(%r{\A#{prefix}?\/}, ''))
      end

      def local_dirname
        @local_dirname = File.dirname(local_path)
      end

      def local_directory_exists?
        Dir.exist?(local_dirname)
      end

      def create_local_directory
        FileUtils.mkdir_p(local_dirname)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deadpull-0.1.1 lib/deadpull/values/local_location.rb
deadpull-0.1.0 lib/deadpull/values/local_location.rb