Sha256: d1a3e130e9d56b2dc701b315265b862927698aa82749b6504110146980c06a08

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 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 "#{self.name}: Selected strategy #{@strategy.class.name}"
        strategy_list << @strategy
	current = @strategy.proposed_options
      end
      raise Uricp::UnsupportedURLtype, "Unsupported transfer from #{options['from_uri']} to #{options['to_uri']}" if incomplete_strategy?(strategy_list)
      strategy_list
    end

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

  private

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uricp-0.0.15 lib/uricp/uri_strategy.rb
uricp-0.0.14 lib/uricp/uri_strategy.rb
uricp-0.0.13 lib/uricp/uri_strategy.rb
uricp-0.0.12 lib/uricp/uri_strategy.rb
uricp-0.0.11 lib/uricp/uri_strategy.rb
uricp-0.0.10 lib/uricp/uri_strategy.rb