Sha256: c04d28d6a6c493f580a82c51fe25cafe01029b2bfdfffba7e7f5b1be082c7225

Contents?: true

Size: 964 Bytes

Versions: 3

Compression:

Stored size: 964 Bytes

Contents

require 'fileutils'

module Uricp::Strategy
  module CacheCommon
    def validate_cache!
      return if dry_run?

      unless cache_exists?
        raise Uricp::MissingCache,
              "no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory"
      end
      return if cache_name

      raise Uricp::MissingCache,
            'no cache name found'
    end

    def in_cache?
      File.readable? cache_file
    end

    def cache_root
      options['cache']
    end

    def cache_name
      options['cache_name']
    end

    def cache_exists?
      cache_root && %w[temp cache].all? do |d|
        File.directory?(File.join(cache_root, d))
      end
    end

    def temp_cache_file
      @temp_cache_file ||= File.join(cache_root, 'temp', cache_name)
    end

    def temp_cache_uri
      URI.join('file:///', temp_cache_file)
    end

    def cache_file
      @cache_file ||= File.join(cache_root, 'cache', cache_name)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uricp-0.0.18 lib/uricp/strategy/cache_common.rb
uricp-0.0.17 lib/uricp/strategy/cache_common.rb
uricp-0.0.16 lib/uricp/strategy/cache_common.rb