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