2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-24 23:51:48 +02:00
|
|
|
# Class corresponding to the `url` stanza.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-07-30 19:48:20 +02:00
|
|
|
class URL
|
|
|
|
ATTRIBUTES = [
|
|
|
|
:using,
|
|
|
|
:tag, :branch, :revisions, :revision,
|
|
|
|
:trust_cert, :cookies, :referer, :user_agent,
|
|
|
|
:data
|
|
|
|
].freeze
|
2020-08-24 23:51:48 +02:00
|
|
|
private_constant :ATTRIBUTES
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2020-07-07 11:29:33 +01:00
|
|
|
attr_reader :uri, :specs, *ATTRIBUTES
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-07-30 19:48:20 +02:00
|
|
|
extend Forwardable
|
|
|
|
def_delegators :uri, :path, :scheme, :to_s
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-08-04 10:13:42 +02:00
|
|
|
def initialize(uri, **options)
|
2018-07-30 19:48:20 +02:00
|
|
|
@uri = URI(uri)
|
|
|
|
@user_agent = :default
|
|
|
|
|
|
|
|
ATTRIBUTES.each do |attribute|
|
|
|
|
next unless options.key?(attribute)
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-07-30 19:48:20 +02:00
|
|
|
instance_variable_set("@#{attribute}", options[attribute])
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2018-08-04 10:13:42 +02:00
|
|
|
|
|
|
|
@specs = options
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|