Sha256: 9279e2f2fd4a1f0c764d1005b51e52f4bb697c20d80020f3e05cb409505c3689

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'uri'

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

    def appropriate?
      if cache_root
        validate_cache!
        return proposal if in_cache? || file_source?

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

    def command
      ':;'
    end

    def proposal
      @proposed_options = options.dup
      @proposed_options['from_uri'] = URI.join('file:///', cache_file) unless file_source?
      @proposed_options.delete('cache')
      @proposed_options.delete('cache_name')
      if conversion_required?
        unless dry_run?
          @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

3 entries across 3 versions & 1 rubygems

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