Sha256: 73137aa99acf2b661629e6429e09857154c334ffbeb6f6b64b910dda225a77d3

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

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::RbdCachedGet,
      Strategy::RbdCacheClone,
      Strategy::RbdCacheCheck,
      Strategy::RbdSnap,
      Strategy::CachedGet,
      Strategy::PipedRemoteGet,
      Strategy::PipedRbdGet,
      Strategy::PipedCacheConvert,
      Strategy::PipedCache,
      Strategy::PipedLocalDecompress,
      Strategy::PipedDecompress,
      Strategy::LocalConvert,
      Strategy::LocalLink,
      Strategy::PipedCompress,
      Strategy::RbdCacheUpload,
      Strategy::RbdCachedPut,
      Strategy::RbdPut,
      Strategy::RbdCacheBaseSnap,
      Strategy::SegmentedRemotePut,
      Strategy::RemotePut,
      Strategy::PipedLocalCompress,
      Strategy::PipedLocalGet,
      Strategy::PipedLocalPut,
      Strategy::Cleaner,
      Strategy::RbdSweeper,
      Strategy::Sweeper
    ].freeze
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
uricp-0.0.34 lib/uricp/uri_strategy.rb
uricp-0.0.32 lib/uricp/uri_strategy.rb
uricp-0.0.31 lib/uricp/uri_strategy.rb
uricp-0.0.30 lib/uricp/uri_strategy.rb
uricp-0.0.29 lib/uricp/uri_strategy.rb
uricp-0.0.28 lib/uricp/uri_strategy.rb
uricp-0.0.27 lib/uricp/uri_strategy.rb
uricp-0.0.26 lib/uricp/uri_strategy.rb
uricp-0.0.25 lib/uricp/uri_strategy.rb