Sha256: e3e0eb9dd17a1261c454a74614b6cb4eefe258c4d693b268f12a81771bbf0cab

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'uri'

module Uricp
  class UriStrategy
    include Methadone::CLILogging

    def self.choose_strategy(options)
      current = options.reject { |k, _v| k.is_a? Symbol }
      strategy_list = []
      while STRATEGIES.detect { |klass| @strategy = klass.new(current).appropriate? }
        debug "#{name}: Selected strategy #{@strategy.class.name}"
        strategy_list << @strategy
        current = @strategy.proposed_options
      end
      if incomplete_strategy?(strategy_list)
        raise Uricp::UnsupportedURLtype, "Unsupported transfer from #{options['from_uri']} to #{options['to_uri']}"
      end

      strategy_list
    end

    def self.incomplete_strategy?(list)
      list.empty?
    end

    # This is an ordered list from the most specific to the most general
    STRATEGIES = [
      Strategy::CachedGet,
      Strategy::PipedRemoteGet,
      Strategy::PipedRbdGet,
      Strategy::PipedCacheConvert,
      Strategy::PipedCache,
      Strategy::PipedLocalDecompress,
      Strategy::PipedDecompress,
      Strategy::LocalConvert,
      Strategy::LocalLink,
      Strategy::PipedCompress,
      Strategy::RbdRemotePut,
      Strategy::SegmentedRemotePut,
      Strategy::RemotePut,
      Strategy::PipedLocalCompress,
      Strategy::PipedLocalGet,
      Strategy::PipedLocalPut,
      Strategy::Cleaner,
      Strategy::RbdSweeper,
      Strategy::Sweeper
    ].freeze
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uricp-0.0.18 lib/uricp/uri_strategy.rb
uricp-0.0.17 lib/uricp/uri_strategy.rb
uricp-0.0.16 lib/uricp/uri_strategy.rb