From 88783eae31c08825baaa5f2df6d336abd1482a42 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 30 Jul 2018 19:48:20 +0200 Subject: [PATCH] Refactor `Hbc::URL` and rename to `URL`. --- Library/Homebrew/cask/lib/hbc/url.rb | 32 +++++++++++-------- .../test/cask/download_strategy_spec.rb | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 0825350e10..cf33855e1a 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -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 diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 0769bb0679..747d034707 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -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") }