Sha256: db354a4e3b14bea16ce1d43d61cb81e745c45f67da0258255abf5439eb22f182

Contents?: true

Size: 902 Bytes

Versions: 5

Compression:

Stored size: 902 Bytes

Contents

require 'fileutils'

module Uricp::Strategy

  module CacheCommon
    
    def validate_cache!
      raise Uricp::MissingCache,
	"no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory" unless cache_exists?
      raise Uricp::MissingCache,
	"no cache name found" unless cache_name
    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

5 entries across 5 versions & 1 rubygems

Version Path
uricp-0.0.15 lib/uricp/strategy/cache_common.rb
uricp-0.0.14 lib/uricp/strategy/cache_common.rb
uricp-0.0.13 lib/uricp/strategy/cache_common.rb
uricp-0.0.12 lib/uricp/strategy/cache_common.rb
uricp-0.0.11 lib/uricp/strategy/cache_common.rb