Sha256: 395a7fa69c0ef494def3b766aacfbaf9fa868706dce5c0f71a42d26e4ce3f510

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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 with_active_cache
      if cache_root
        yield
      else
        debug "#{self.class.name}: no cacheing requested"
        false
      end
    end

    def without_active_cache
      if cache_root
        debug "#{self.class.name}: cache active - not appropriate"
        false
      else
        yield
      end
    end

    def in_cache?
      File.readable?(cache_file) || options['dry-cache'] == :rbd
    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

12 entries across 12 versions & 1 rubygems

Version Path
uricp-0.0.37 lib/uricp/strategy/cache_common.rb
uricp-0.0.36 lib/uricp/strategy/cache_common.rb
uricp-0.0.35 lib/uricp/strategy/cache_common.rb
uricp-0.0.34 lib/uricp/strategy/cache_common.rb
uricp-0.0.32 lib/uricp/strategy/cache_common.rb
uricp-0.0.31 lib/uricp/strategy/cache_common.rb
uricp-0.0.30 lib/uricp/strategy/cache_common.rb
uricp-0.0.29 lib/uricp/strategy/cache_common.rb
uricp-0.0.28 lib/uricp/strategy/cache_common.rb
uricp-0.0.27 lib/uricp/strategy/cache_common.rb
uricp-0.0.26 lib/uricp/strategy/cache_common.rb
uricp-0.0.25 lib/uricp/strategy/cache_common.rb