Refactor Hbc::URL and rename to URL.
				
					
				
			This commit is contained in:
		
							parent
							
								
									54aa412015
								
							
						
					
					
						commit
						88783eae31
					
				@ -1,20 +1,24 @@
 | 
			
		||||
module Hbc
 | 
			
		||||
  class URL
 | 
			
		||||
    attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data, :user_agent
 | 
			
		||||
class URL
 | 
			
		||||
  ATTRIBUTES = [
 | 
			
		||||
    :using,
 | 
			
		||||
    :tag, :branch, :revisions, :revision,
 | 
			
		||||
    :trust_cert, :cookies, :referer, :user_agent,
 | 
			
		||||
    :data
 | 
			
		||||
  ].freeze
 | 
			
		||||
 | 
			
		||||
    extend Forwardable
 | 
			
		||||
    def_delegators :uri, :path, :scheme, :to_s
 | 
			
		||||
  attr_reader :uri
 | 
			
		||||
  attr_reader(*ATTRIBUTES)
 | 
			
		||||
 | 
			
		||||
  extend Forwardable
 | 
			
		||||
  def_delegators :uri, :path, :scheme, :to_s
 | 
			
		||||
 | 
			
		||||
    def initialize(uri, options = {})
 | 
			
		||||
      @uri        = URI(uri)
 | 
			
		||||
      @user_agent = options.fetch(:user_agent, :default)
 | 
			
		||||
      @cookies    = options[:cookies]
 | 
			
		||||
      @referer    = options[:referer]
 | 
			
		||||
      @using      = options[:using]
 | 
			
		||||
      @revision   = options[:revision]
 | 
			
		||||
      @trust_cert = options[:trust_cert]
 | 
			
		||||
      @data       = options[:data]
 | 
			
		||||
  def initialize(uri, options = {})
 | 
			
		||||
    @uri        = URI(uri)
 | 
			
		||||
    @user_agent = :default
 | 
			
		||||
 | 
			
		||||
    ATTRIBUTES.each do |attribute|
 | 
			
		||||
      next unless options.key?(attribute)
 | 
			
		||||
      instance_variable_set("@#{attribute}", options[attribute])
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@ describe "download strategies", :cask do
 | 
			
		||||
  let(:url_options) { {} }
 | 
			
		||||
  let(:cask) {
 | 
			
		||||
    instance_double(Hbc::Cask, token:   "some-cask",
 | 
			
		||||
                               url:     Hbc::URL.new(url, url_options),
 | 
			
		||||
                               url:     URL.new(url, **url_options),
 | 
			
		||||
                               version: "1.2.3.4")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user