Sha256: f2bd9c73da5d8bbd95c2139136319ec75d7c060cf89fe5b772d389ab96f13373

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require 'uri'

module Uricp::Strategy
  class CachedGet
    include Uricp::Strategy::Common
    include Uricp::Strategy::CacheCommon

    def appropriate?
      with_active_cache do
        validate_cache!
        return proposal if in_cache? || file_source?

        debug "#{self.class.name}: no cache entry for #{options['from_uri']}"
        false
      end
    end

    def command
      ':;'
    end

    def proposal
      @proposed_options = options.dup
      @proposed_options['from_uri'] = URI.join('file:///', cache_file) unless file_source?
      if to.scheme == 'rbd'
        @proposed_options['rbd_cache_name'] = rbd_cache_image_spec(to)
      end
      @proposed_options.delete('cache')
      @proposed_options.delete('cache_name')
      if conversion_required?
        if dry_run?
          @proposed_options['source-format'] = @proposed_options['target-format']
        else
          @proposed_options['source-format'] =
            File.open(@proposed_options['from_uri'].path) { |f| encoding(f) }
        end
        if @proposed_options['source-format'] == @proposed_options['target-format']
          @proposed_options.delete('source-format')
          @proposed_options.delete('target-format')
        end
      end
      self
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
uricp-0.0.24 lib/uricp/strategy/cached_get.rb
uricp-0.0.23 lib/uricp/strategy/cached_get.rb
uricp-0.0.22 lib/uricp/strategy/cached_get.rb
uricp-0.0.21 lib/uricp/strategy/cached_get.rb
uricp-0.0.20 lib/uricp/strategy/cached_get.rb