true
if the Template objects are equal. This method
- # does NOT normalize either Template before doing the comparison.
- #
- # @param [Object] template The Template to compare.
- #
- # @return [TrueClass, FalseClass]
- # true
if the Templates are equivalent, false
- # otherwise.
- def ==(template)
- return false unless template.kind_of?(Template)
- return self.pattern == template.pattern
- end
-
- ##
- # Addressable::Template makes no distinction between `==` and `eql?`.
- #
- # @see #==
- alias_method :eql?, :==
-
- ##
- # Extracts a mapping from the URI using a URI Template pattern.
- #
- # @param [Addressable::URI, #to_str] uri
- # The URI to extract from.
- #
- # @param [#restore, #match] processor
- # A template processor object may optionally be supplied.
- #
- # The object should respond to either the restore or
- # match messages or both. The restore method should
- # take two parameters: `[String] name` and `[String] value`.
- # The restore method should reverse any transformations that
- # have been performed on the value to ensure a valid URI.
- # The match method should take a single
- # parameter: `[String] name`. The match method should return
- # a String containing a regular expression capture group for
- # matching on that particular variable. The default value is `".*?"`.
- # The match method has no effect on multivariate operator
- # expansions.
- #
- # @return [Hash, NilClass]
- # The Hash mapping that was extracted from the URI, or
- # nil if the URI didn't match the template.
- #
- # @example
- # class ExampleProcessor
- # def self.restore(name, value)
- # return value.gsub(/\+/, " ") if name == "query"
- # return value
- # end
- #
- # def self.match(name)
- # return ".*?" if name == "first"
- # return ".*"
- # end
- # end
- #
- # uri = Addressable::URI.parse(
- # "http://example.com/search/an+example+search+query/"
- # )
- # Addressable::Template.new(
- # "http://example.com/search/{query}/"
- # ).extract(uri, ExampleProcessor)
- # #=> {"query" => "an example search query"}
- #
- # uri = Addressable::URI.parse("http://example.com/a/b/c/")
- # Addressable::Template.new(
- # "http://example.com/{first}/{second}/"
- # ).extract(uri, ExampleProcessor)
- # #=> {"first" => "a", "second" => "b/c"}
- #
- # uri = Addressable::URI.parse("http://example.com/a/b/c/")
- # Addressable::Template.new(
- # "http://example.com/{first}/{-list|/|second}/"
- # ).extract(uri)
- # #=> {"first" => "a", "second" => ["b", "c"]}
- def extract(uri, processor=nil)
- match_data = self.match(uri, processor)
- return (match_data ? match_data.mapping : nil)
- end
-
- ##
- # Extracts match data from the URI using a URI Template pattern.
- #
- # @param [Addressable::URI, #to_str] uri
- # The URI to extract from.
- #
- # @param [#restore, #match] processor
- # A template processor object may optionally be supplied.
- #
- # The object should respond to either the restore or
- # match messages or both. The restore method should
- # take two parameters: `[String] name` and `[String] value`.
- # The restore method should reverse any transformations that
- # have been performed on the value to ensure a valid URI.
- # The match method should take a single
- # parameter: `[String] name`. The match method should return
- # a String containing a regular expression capture group for
- # matching on that particular variable. The default value is `".*?"`.
- # The match method has no effect on multivariate operator
- # expansions.
- #
- # @return [Hash, NilClass]
- # The Hash mapping that was extracted from the URI, or
- # nil if the URI didn't match the template.
- #
- # @example
- # class ExampleProcessor
- # def self.restore(name, value)
- # return value.gsub(/\+/, " ") if name == "query"
- # return value
- # end
- #
- # def self.match(name)
- # return ".*?" if name == "first"
- # return ".*"
- # end
- # end
- #
- # uri = Addressable::URI.parse(
- # "http://example.com/search/an+example+search+query/"
- # )
- # match = Addressable::Template.new(
- # "http://example.com/search/{query}/"
- # ).match(uri, ExampleProcessor)
- # match.variables
- # #=> ["query"]
- # match.captures
- # #=> ["an example search query"]
- #
- # uri = Addressable::URI.parse("http://example.com/a/b/c/")
- # match = Addressable::Template.new(
- # "http://example.com/{first}/{+second}/"
- # ).match(uri, ExampleProcessor)
- # match.variables
- # #=> ["first", "second"]
- # match.captures
- # #=> ["a", "b/c"]
- #
- # uri = Addressable::URI.parse("http://example.com/a/b/c/")
- # match = Addressable::Template.new(
- # "http://example.com/{first}{/second*}/"
- # ).match(uri)
- # match.variables
- # #=> ["first", "second"]
- # match.captures
- # #=> ["a", ["b", "c"]]
- def match(uri, processor=nil)
- uri = Addressable::URI.parse(uri) unless uri.is_a?(Addressable::URI)
- mapping = {}
-
- # First, we need to process the pattern, and extract the values.
- expansions, expansion_regexp =
- parse_template_pattern(pattern, processor)
-
- return nil unless uri.to_str.match(expansion_regexp)
- unparsed_values = uri.to_str.scan(expansion_regexp).flatten
-
- if uri.to_str == pattern
- return Addressable::Template::MatchData.new(uri, self, mapping)
- elsif expansions.size > 0
- index = 0
- expansions.each do |expansion|
- _, operator, varlist = *expansion.match(EXPRESSION)
- varlist.split(',').each do |varspec|
- _, name, modifier = *varspec.match(VARSPEC)
- mapping[name] ||= nil
- case operator
- when nil, '+', '#', '/', '.'
- unparsed_value = unparsed_values[index]
- name = varspec[VARSPEC, 1]
- value = unparsed_value
- value = value.split(JOINERS[operator]) if value && modifier == '*'
- when ';', '?', '&'
- if modifier == '*'
- if unparsed_values[index]
- value = unparsed_values[index].split(JOINERS[operator])
- value = value.inject({}) do |acc, v|
- key, val = v.split('=')
- val = "" if val.nil?
- acc[key] = val
- acc
- end
- end
- else
- if (unparsed_values[index])
- name, value = unparsed_values[index].split('=')
- value = "" if value.nil?
- end
- end
- end
- if processor != nil && processor.respond_to?(:restore)
- value = processor.restore(name, value)
- end
- if processor == nil
- if value.is_a?(Hash)
- value = value.inject({}){|acc, (k, v)|
- acc[Addressable::URI.unencode_component(k)] =
- Addressable::URI.unencode_component(v)
- acc
- }
- elsif value.is_a?(Array)
- value = value.map{|v| Addressable::URI.unencode_component(v) }
- else
- value = Addressable::URI.unencode_component(value)
- end
- end
- if !mapping.has_key?(name) || mapping[name].nil?
- # Doesn't exist, set to value (even if value is nil)
- mapping[name] = value
- end
- index = index + 1
- end
- end
- return Addressable::Template::MatchData.new(uri, self, mapping)
- else
- return nil
- end
- end
-
- ##
- # Expands a URI template into another URI template.
- #
- # @param [Hash] mapping The mapping that corresponds to the pattern.
- # @param [#validate, #transform] processor
- # An optional processor object may be supplied.
- # @param [Boolean] normalize_values
- # Optional flag to enable/disable unicode normalization. Default: true
- #
- # The object should respond to either the validate or
- # transform messages or both. Both the validate and
- # transform methods should take two parameters: name and
- # value. The validate method should return true
- # or false; true if the value of the variable is valid,
- # false otherwise. An InvalidTemplateValueError
- # exception will be raised if the value is invalid. The transform
- # method should return the transformed variable value as a String.
- # If a transform method is used, the value will not be percent
- # encoded automatically. Unicode normalization will be performed both
- # before and after sending the value to the transform method.
- #
- # @return [Addressable::Template] The partially expanded URI template.
- #
- # @example
- # Addressable::Template.new(
- # "http://example.com/{one}/{two}/"
- # ).partial_expand({"one" => "1"}).pattern
- # #=> "http://example.com/1/{two}/"
- #
- # Addressable::Template.new(
- # "http://example.com/{?one,two}/"
- # ).partial_expand({"one" => "1"}).pattern
- # #=> "http://example.com/?one=1{&two}/"
- #
- # Addressable::Template.new(
- # "http://example.com/{?one,two,three}/"
- # ).partial_expand({"one" => "1", "three" => 3}).pattern
- # #=> "http://example.com/?one=1{&two}&three=3"
- def partial_expand(mapping, processor=nil, normalize_values=true)
- result = self.pattern.dup
- mapping = normalize_keys(mapping)
- result.gsub!( EXPRESSION ) do |capture|
- transform_partial_capture(mapping, capture, processor, normalize_values)
- end
- return Addressable::Template.new(result)
- end
-
- ##
- # Expands a URI template into a full URI.
- #
- # @param [Hash] mapping The mapping that corresponds to the pattern.
- # @param [#validate, #transform] processor
- # An optional processor object may be supplied.
- # @param [Boolean] normalize_values
- # Optional flag to enable/disable unicode normalization. Default: true
- #
- # The object should respond to either the validate or
- # transform messages or both. Both the validate and
- # transform methods should take two parameters: name and
- # value. The validate method should return true
- # or false; true if the value of the variable is valid,
- # false otherwise. An InvalidTemplateValueError
- # exception will be raised if the value is invalid. The transform
- # method should return the transformed variable value as a String.
- # If a transform method is used, the value will not be percent
- # encoded automatically. Unicode normalization will be performed both
- # before and after sending the value to the transform method.
- #
- # @return [Addressable::URI] The expanded URI template.
- #
- # @example
- # class ExampleProcessor
- # def self.validate(name, value)
- # return !!(value =~ /^[\w ]+$/) if name == "query"
- # return true
- # end
- #
- # def self.transform(name, value)
- # return value.gsub(/ /, "+") if name == "query"
- # return value
- # end
- # end
- #
- # Addressable::Template.new(
- # "http://example.com/search/{query}/"
- # ).expand(
- # {"query" => "an example search query"},
- # ExampleProcessor
- # ).to_str
- # #=> "http://example.com/search/an+example+search+query/"
- #
- # Addressable::Template.new(
- # "http://example.com/search/{query}/"
- # ).expand(
- # {"query" => "an example search query"}
- # ).to_str
- # #=> "http://example.com/search/an%20example%20search%20query/"
- #
- # Addressable::Template.new(
- # "http://example.com/search/{query}/"
- # ).expand(
- # {"query" => "bogus!"},
- # ExampleProcessor
- # ).to_str
- # #=> Addressable::Template::InvalidTemplateValueError
- def expand(mapping, processor=nil, normalize_values=true)
- result = self.pattern.dup
- mapping = normalize_keys(mapping)
- result.gsub!( EXPRESSION ) do |capture|
- transform_capture(mapping, capture, processor, normalize_values)
- end
- return Addressable::URI.parse(result)
- end
-
- ##
- # Returns an Array of variables used within the template pattern.
- # The variables are listed in the Array in the order they appear within
- # the pattern. Multiple occurrences of a variable within a pattern are
- # not represented in this Array.
- #
- # @return [Array] The variables present in the template's pattern.
- def variables
- @variables ||= ordered_variable_defaults.map { |var, val| var }.uniq
- end
- alias_method :keys, :variables
- alias_method :names, :variables
-
- ##
- # Returns a mapping of variables to their default values specified
- # in the template. Variables without defaults are not returned.
- #
- # @return [Hash] Mapping of template variables to their defaults
- def variable_defaults
- @variable_defaults ||=
- Hash[*ordered_variable_defaults.reject { |k, v| v.nil? }.flatten]
- end
-
- ##
- # Coerces a template into a `Regexp` object. This regular expression will
- # behave very similarly to the actual template, and should match the same
- # URI values, but it cannot fully handle, for example, values that would
- # extract to an `Array`.
- #
- # @return [Regexp] A regular expression which should match the template.
- def to_regexp
- _, source = parse_template_pattern(pattern)
- Regexp.new(source)
- end
-
- ##
- # Returns the source of the coerced `Regexp`.
- #
- # @return [String] The source of the `Regexp` given by {#to_regexp}.
- #
- # @api private
- def source
- self.to_regexp.source
- end
-
- ##
- # Returns the named captures of the coerced `Regexp`.
- #
- # @return [Hash] The named captures of the `Regexp` given by {#to_regexp}.
- #
- # @api private
- def named_captures
- self.to_regexp.named_captures
- end
-
- private
- def ordered_variable_defaults
- @ordered_variable_defaults ||= begin
- expansions, _ = parse_template_pattern(pattern)
- expansions.flat_map do |capture|
- _, _, varlist = *capture.match(EXPRESSION)
- varlist.split(',').map do |varspec|
- varspec[VARSPEC, 1]
- end
- end
- end
- end
-
-
- ##
- # Loops through each capture and expands any values available in mapping
- #
- # @param [Hash] mapping
- # Set of keys to expand
- # @param [String] capture
- # The expression to expand
- # @param [#validate, #transform] processor
- # An optional processor object may be supplied.
- # @param [Boolean] normalize_values
- # Optional flag to enable/disable unicode normalization. Default: true
- #
- # The object should respond to either the validate or
- # transform messages or both. Both the validate and
- # transform methods should take two parameters: name and
- # value. The validate method should return true
- # or false; true if the value of the variable is valid,
- # false otherwise. An InvalidTemplateValueError exception
- # will be raised if the value is invalid. The transform method
- # should return the transformed variable value as a String. If a
- # transform method is used, the value will not be percent encoded
- # automatically. Unicode normalization will be performed both before and
- # after sending the value to the transform method.
- #
- # @return [String] The expanded expression
- def transform_partial_capture(mapping, capture, processor = nil,
- normalize_values = true)
- _, operator, varlist = *capture.match(EXPRESSION)
-
- vars = varlist.split(",")
-
- if operator == "?"
- # partial expansion of form style query variables sometimes requires a
- # slight reordering of the variables to produce a valid url.
- first_to_expand = vars.find { |varspec|
- _, name, _ = *varspec.match(VARSPEC)
- mapping.key?(name) && !mapping[name].nil?
- }
-
- vars = [first_to_expand] + vars.reject {|varspec| varspec == first_to_expand} if first_to_expand
- end
-
- vars.
- inject("".dup) do |acc, varspec|
- _, name, _ = *varspec.match(VARSPEC)
- next_val = if mapping.key? name
- transform_capture(mapping, "{#{operator}#{varspec}}",
- processor, normalize_values)
- else
- "{#{operator}#{varspec}}"
- end
- # If we've already expanded at least one '?' operator with non-empty
- # value, change to '&'
- operator = "&" if (operator == "?") && (next_val != "")
- acc << next_val
- end
- end
-
- ##
- # Transforms a mapped value so that values can be substituted into the
- # template.
- #
- # @param [Hash] mapping The mapping to replace captures
- # @param [String] capture
- # The expression to replace
- # @param [#validate, #transform] processor
- # An optional processor object may be supplied.
- # @param [Boolean] normalize_values
- # Optional flag to enable/disable unicode normalization. Default: true
- #
- #
- # The object should respond to either the validate or
- # transform messages or both. Both the validate and
- # transform methods should take two parameters: name and
- # value. The validate method should return true
- # or false; true if the value of the variable is valid,
- # false otherwise. An InvalidTemplateValueError exception
- # will be raised if the value is invalid. The transform method
- # should return the transformed variable value as a String. If a
- # transform method is used, the value will not be percent encoded
- # automatically. Unicode normalization will be performed both before and
- # after sending the value to the transform method.
- #
- # @return [String] The expanded expression
- def transform_capture(mapping, capture, processor=nil,
- normalize_values=true)
- _, operator, varlist = *capture.match(EXPRESSION)
- return_value = varlist.split(',').inject([]) do |acc, varspec|
- _, name, modifier = *varspec.match(VARSPEC)
- value = mapping[name]
- unless value == nil || value == {}
- allow_reserved = %w(+ #).include?(operator)
- # Common primitives where the .to_s output is well-defined
- if Numeric === value || Symbol === value ||
- value == true || value == false
- value = value.to_s
- end
- length = modifier.gsub(':', '').to_i if modifier =~ /^:\d+/
-
- unless (Hash === value) ||
- value.respond_to?(:to_ary) || value.respond_to?(:to_str)
- raise TypeError,
- "Can't convert #{value.class} into String or Array."
- end
-
- value = normalize_value(value) if normalize_values
-
- if processor == nil || !processor.respond_to?(:transform)
- # Handle percent escaping
- if allow_reserved
- encode_map =
- Addressable::URI::CharacterClasses::RESERVED +
- Addressable::URI::CharacterClasses::UNRESERVED
- else
- encode_map = Addressable::URI::CharacterClasses::UNRESERVED
- end
- if value.kind_of?(Array)
- transformed_value = value.map do |val|
- if length
- Addressable::URI.encode_component(val[0...length], encode_map)
- else
- Addressable::URI.encode_component(val, encode_map)
- end
- end
- unless modifier == "*"
- transformed_value = transformed_value.join(',')
- end
- elsif value.kind_of?(Hash)
- transformed_value = value.map do |key, val|
- if modifier == "*"
- "#{
- Addressable::URI.encode_component( key, encode_map)
- }=#{
- Addressable::URI.encode_component( val, encode_map)
- }"
- else
- "#{
- Addressable::URI.encode_component( key, encode_map)
- },#{
- Addressable::URI.encode_component( val, encode_map)
- }"
- end
- end
- unless modifier == "*"
- transformed_value = transformed_value.join(',')
- end
- else
- if length
- transformed_value = Addressable::URI.encode_component(
- value[0...length], encode_map)
- else
- transformed_value = Addressable::URI.encode_component(
- value, encode_map)
- end
- end
- end
-
- # Process, if we've got a processor
- if processor != nil
- if processor.respond_to?(:validate)
- if !processor.validate(name, value)
- display_value = value.kind_of?(Array) ? value.inspect : value
- raise InvalidTemplateValueError,
- "#{name}=#{display_value} is an invalid template value."
- end
- end
- if processor.respond_to?(:transform)
- transformed_value = processor.transform(name, value)
- if normalize_values
- transformed_value = normalize_value(transformed_value)
- end
- end
- end
- acc << [name, transformed_value]
- end
- acc
- end
- return "" if return_value.empty?
- join_values(operator, return_value)
- end
-
- ##
- # Takes a set of values, and joins them together based on the
- # operator.
- #
- # @param [String, Nil] operator One of the operators from the set
- # (?,&,+,#,;,/,.), or nil if there wasn't one.
- # @param [Array] return_value
- # The set of return values (as [variable_name, value] tuples) that will
- # be joined together.
- #
- # @return [String] The transformed mapped value
- def join_values(operator, return_value)
- leader = LEADERS.fetch(operator, '')
- joiner = JOINERS.fetch(operator, ',')
- case operator
- when '&', '?'
- leader + return_value.map{|k,v|
- if v.is_a?(Array) && v.first =~ /=/
- v.join(joiner)
- elsif v.is_a?(Array)
- v.map{|inner_value| "#{k}=#{inner_value}"}.join(joiner)
- else
- "#{k}=#{v}"
- end
- }.join(joiner)
- when ';'
- return_value.map{|k,v|
- if v.is_a?(Array) && v.first =~ /=/
- ';' + v.join(";")
- elsif v.is_a?(Array)
- ';' + v.map{|inner_value| "#{k}=#{inner_value}"}.join(";")
- else
- v && v != '' ? ";#{k}=#{v}" : ";#{k}"
- end
- }.join
- else
- leader + return_value.map{|k,v| v}.join(joiner)
- end
- end
-
- ##
- # Takes a set of values, and joins them together based on the
- # operator.
- #
- # @param [Hash, Array, String] value
- # Normalizes unicode keys and values with String#unicode_normalize (NFC)
- #
- # @return [Hash, Array, String] The normalized values
- def normalize_value(value)
- # Handle unicode normalization
- if value.respond_to?(:to_ary)
- value.to_ary.map! { |val| normalize_value(val) }
- elsif value.kind_of?(Hash)
- value = value.inject({}) { |acc, (k, v)|
- acc[normalize_value(k)] = normalize_value(v)
- acc
- }
- else
- value = value.to_s if !value.kind_of?(String)
- if value.encoding != Encoding::UTF_8
- value = value.dup.force_encoding(Encoding::UTF_8)
- end
- value = value.unicode_normalize(:nfc)
- end
- value
- end
-
- ##
- # Generates a hash with string keys
- #
- # @param [Hash] mapping A mapping hash to normalize
- #
- # @return [Hash]
- # A hash with stringified keys
- def normalize_keys(mapping)
- return mapping.inject({}) do |accu, pair|
- name, value = pair
- if Symbol === name
- name = name.to_s
- elsif name.respond_to?(:to_str)
- name = name.to_str
- else
- raise TypeError,
- "Can't convert #{name.class} into String."
- end
- accu[name] = value
- accu
- end
- end
-
- ##
- # Generates the Regexp that parses a template pattern. Memoizes the
- # value if template processor not set (processors may not be deterministic)
- #
- # @param [String] pattern The URI template pattern.
- # @param [#match] processor The template processor to use.
- #
- # @return [Array, Regexp]
- # An array of expansion variables nad a regular expression which may be
- # used to parse a template pattern
- def parse_template_pattern(pattern, processor = nil)
- if processor.nil? && pattern == @pattern
- @cached_template_parse ||=
- parse_new_template_pattern(pattern, processor)
- else
- parse_new_template_pattern(pattern, processor)
- end
- end
-
- ##
- # Generates the Regexp that parses a template pattern.
- #
- # @param [String] pattern The URI template pattern.
- # @param [#match] processor The template processor to use.
- #
- # @return [Array, Regexp]
- # An array of expansion variables nad a regular expression which may be
- # used to parse a template pattern
- def parse_new_template_pattern(pattern, processor = nil)
- # Escape the pattern. The two gsubs restore the escaped curly braces
- # back to their original form. Basically, escape everything that isn't
- # within an expansion.
- escaped_pattern = Regexp.escape(
- pattern
- ).gsub(/\\\{(.*?)\\\}/) do |escaped|
- escaped.gsub(/\\(.)/, "\\1")
- end
-
- expansions = []
-
- # Create a regular expression that captures the values of the
- # variables in the URI.
- regexp_string = escaped_pattern.gsub( EXPRESSION ) do |expansion|
-
- expansions << expansion
- _, operator, varlist = *expansion.match(EXPRESSION)
- leader = Regexp.escape(LEADERS.fetch(operator, ''))
- joiner = Regexp.escape(JOINERS.fetch(operator, ','))
- combined = varlist.split(',').map do |varspec|
- _, name, modifier = *varspec.match(VARSPEC)
-
- result = processor && processor.respond_to?(:match) ? processor.match(name) : nil
- if result
- "(?<#{name}>#{ result })"
- else
- group = case operator
- when '+'
- "#{ RESERVED }*?"
- when '#'
- "#{ RESERVED }*?"
- when '/'
- "#{ UNRESERVED }*?"
- when '.'
- "#{ UNRESERVED.gsub('\.', '') }*?"
- when ';'
- "#{ UNRESERVED }*=?#{ UNRESERVED }*?"
- when '?'
- "#{ UNRESERVED }*=#{ UNRESERVED }*?"
- when '&'
- "#{ UNRESERVED }*=#{ UNRESERVED }*?"
- else
- "#{ UNRESERVED }*?"
- end
- if modifier == '*'
- "(?<#{name}>#{group}(?:#{joiner}?#{group})*)?"
- else
- "(?<#{name}>#{group})?"
- end
- end
- end.join("#{joiner}?")
- "(?:|#{leader}#{combined})"
- end
-
- # Ensure that the regular expression matches the whole URI.
- regexp_string = "\\A#{regexp_string}\\z"
- return expansions, Regexp.new(regexp_string)
- end
-
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/addressable-2.8.5/lib/addressable/uri.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/addressable-2.8.5/lib/addressable/uri.rb
deleted file mode 100644
index 08ee3348a79c0..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/addressable-2.8.5/lib/addressable/uri.rb
+++ /dev/null
@@ -1,2591 +0,0 @@
-# frozen_string_literal: true
-
-#--
-# Copyright (C) Bob Aman
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#++
-
-
-require "addressable/version"
-require "addressable/idna"
-require "public_suffix"
-
-##
-# Addressable is a library for processing links and URIs.
-module Addressable
- ##
- # This is an implementation of a URI parser based on
- # RFC 3986,
- # RFC 3987.
- class URI
- ##
- # Raised if something other than a uri is supplied.
- class InvalidURIError < StandardError
- end
-
- ##
- # Container for the character classes specified in
- # RFC 3986.
- #
- # Note: Concatenated and interpolated `String`s are not affected by the
- # `frozen_string_literal` directive and must be frozen explicitly.
- #
- # Interpolated `String`s *were* frozen this way before Ruby 3.0:
- # https://bugs.ruby-lang.org/issues/17104
- module CharacterClasses
- ALPHA = "a-zA-Z"
- DIGIT = "0-9"
- GEN_DELIMS = "\\:\\/\\?\\#\\[\\]\\@"
- SUB_DELIMS = "\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\="
- RESERVED = (GEN_DELIMS + SUB_DELIMS).freeze
- UNRESERVED = (ALPHA + DIGIT + "\\-\\.\\_\\~").freeze
- PCHAR = (UNRESERVED + SUB_DELIMS + "\\:\\@").freeze
- SCHEME = (ALPHA + DIGIT + "\\-\\+\\.").freeze
- HOST = (UNRESERVED + SUB_DELIMS + "\\[\\:\\]").freeze
- AUTHORITY = (PCHAR + "\\[\\]").freeze
- PATH = (PCHAR + "\\/").freeze
- QUERY = (PCHAR + "\\/\\?").freeze
- FRAGMENT = (PCHAR + "\\/\\?").freeze
- end
-
- module NormalizeCharacterClasses
- HOST = /[^#{CharacterClasses::HOST}]/
- UNRESERVED = /[^#{CharacterClasses::UNRESERVED}]/
- PCHAR = /[^#{CharacterClasses::PCHAR}]/
- SCHEME = /[^#{CharacterClasses::SCHEME}]/
- FRAGMENT = /[^#{CharacterClasses::FRAGMENT}]/
- QUERY = %r{[^a-zA-Z0-9\-\.\_\~\!\$\'\(\)\*\+\,\=\:\@\/\?%]|%(?!2B|2b)}
- end
-
- SLASH = '/'
- EMPTY_STR = ''
-
- URIREGEX = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/
-
- PORT_MAPPING = {
- "http" => 80,
- "https" => 443,
- "ftp" => 21,
- "tftp" => 69,
- "sftp" => 22,
- "ssh" => 22,
- "svn+ssh" => 22,
- "telnet" => 23,
- "nntp" => 119,
- "gopher" => 70,
- "wais" => 210,
- "ldap" => 389,
- "prospero" => 1525
- }.freeze
-
- ##
- # Returns a URI object based on the parsed string.
- #
- # @param [String, Addressable::URI, #to_str] uri
- # The URI string to parse.
- # No parsing is performed if the object is already an
- # Addressable::URI
.
- #
- # @return [Addressable::URI] The parsed URI.
- def self.parse(uri)
- # If we were given nil, return nil.
- return nil unless uri
- # If a URI object is passed, just return itself.
- return uri.dup if uri.kind_of?(self)
-
- # If a URI object of the Ruby standard library variety is passed,
- # convert it to a string, then parse the string.
- # We do the check this way because we don't want to accidentally
- # cause a missing constant exception to be thrown.
- if uri.class.name =~ /^URI\b/
- uri = uri.to_s
- end
-
- # Otherwise, convert to a String
- begin
- uri = uri.to_str
- rescue TypeError, NoMethodError
- raise TypeError, "Can't convert #{uri.class} into String."
- end unless uri.is_a?(String)
-
- # This Regexp supplied as an example in RFC 3986, and it works great.
- scan = uri.scan(URIREGEX)
- fragments = scan[0]
- scheme = fragments[1]
- authority = fragments[3]
- path = fragments[4]
- query = fragments[6]
- fragment = fragments[8]
- user = nil
- password = nil
- host = nil
- port = nil
- if authority != nil
- # The Regexp above doesn't split apart the authority.
- userinfo = authority[/^([^\[\]]*)@/, 1]
- if userinfo != nil
- user = userinfo.strip[/^([^:]*):?/, 1]
- password = userinfo.strip[/:(.*)$/, 1]
- end
-
- host = authority.sub(
- /^([^\[\]]*)@/, EMPTY_STR
- ).sub(
- /:([^:@\[\]]*?)$/, EMPTY_STR
- )
-
- port = authority[/:([^:@\[\]]*?)$/, 1]
- port = nil if port == EMPTY_STR
- end
-
- return new(
- :scheme => scheme,
- :user => user,
- :password => password,
- :host => host,
- :port => port,
- :path => path,
- :query => query,
- :fragment => fragment
- )
- end
-
- ##
- # Converts an input to a URI. The input does not have to be a valid
- # URI — the method will use heuristics to guess what URI was intended.
- # This is not standards-compliant, merely user-friendly.
- #
- # @param [String, Addressable::URI, #to_str] uri
- # The URI string to parse.
- # No parsing is performed if the object is already an
- # Addressable::URI
.
- # @param [Hash] hints
- # A Hash
of hints to the heuristic parser.
- # Defaults to {:scheme => "http"}
.
- #
- # @return [Addressable::URI] The parsed URI.
- def self.heuristic_parse(uri, hints={})
- # If we were given nil, return nil.
- return nil unless uri
- # If a URI object is passed, just return itself.
- return uri.dup if uri.kind_of?(self)
-
- # If a URI object of the Ruby standard library variety is passed,
- # convert it to a string, then parse the string.
- # We do the check this way because we don't want to accidentally
- # cause a missing constant exception to be thrown.
- if uri.class.name =~ /^URI\b/
- uri = uri.to_s
- end
-
- unless uri.respond_to?(:to_str)
- raise TypeError, "Can't convert #{uri.class} into String."
- end
- # Otherwise, convert to a String
- uri = uri.to_str.dup.strip
- hints = {
- :scheme => "http"
- }.merge(hints)
- case uri
- when /^http:\//i
- uri.sub!(/^http:\/+/i, "http://")
- when /^https:\//i
- uri.sub!(/^https:\/+/i, "https://")
- when /^feed:\/+http:\//i
- uri.sub!(/^feed:\/+http:\/+/i, "feed:http://")
- when /^feed:\//i
- uri.sub!(/^feed:\/+/i, "feed://")
- when %r[^file:/{4}]i
- uri.sub!(%r[^file:/+]i, "file:////")
- when %r[^file://localhost/]i
- uri.sub!(%r[^file://localhost/+]i, "file:///")
- when %r[^file:/+]i
- uri.sub!(%r[^file:/+]i, "file:///")
- when /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
- uri.sub!(/^/, hints[:scheme] + "://")
- when /\A\d+\..*:\d+\z/
- uri = "#{hints[:scheme]}://#{uri}"
- end
- match = uri.match(URIREGEX)
- fragments = match.captures
- authority = fragments[3]
- if authority && authority.length > 0
- new_authority = authority.tr("\\", "/").gsub(" ", "%20")
- # NOTE: We want offset 4, not 3!
- offset = match.offset(4)
- uri = uri.dup
- uri[offset[0]...offset[1]] = new_authority
- end
- parsed = self.parse(uri)
- if parsed.scheme =~ /^[^\/?#\.]+\.[^\/?#]+$/
- parsed = self.parse(hints[:scheme] + "://" + uri)
- end
- if parsed.path.include?(".")
- if parsed.path[/\b@\b/]
- parsed.scheme = "mailto" unless parsed.scheme
- elsif new_host = parsed.path[/^([^\/]+\.[^\/]*)/, 1]
- parsed.defer_validation do
- new_path = parsed.path.sub(
- Regexp.new("^" + Regexp.escape(new_host)), EMPTY_STR)
- parsed.host = new_host
- parsed.path = new_path
- parsed.scheme = hints[:scheme] unless parsed.scheme
- end
- end
- end
- return parsed
- end
-
- ##
- # Converts a path to a file scheme URI. If the path supplied is
- # relative, it will be returned as a relative URI. If the path supplied
- # is actually a non-file URI, it will parse the URI as if it had been
- # parsed with Addressable::URI.parse
. Handles all of the
- # various Microsoft-specific formats for specifying paths.
- #
- # @param [String, Addressable::URI, #to_str] path
- # Typically a String
path to a file or directory, but
- # will return a sensible return value if an absolute URI is supplied
- # instead.
- #
- # @return [Addressable::URI]
- # The parsed file scheme URI or the original URI if some other URI
- # scheme was provided.
- #
- # @example
- # base = Addressable::URI.convert_path("/absolute/path/")
- # uri = Addressable::URI.convert_path("relative/path")
- # (base + uri).to_s
- # #=> "file:///absolute/path/relative/path"
- #
- # Addressable::URI.convert_path(
- # "c:\\windows\\My Documents 100%20\\foo.txt"
- # ).to_s
- # #=> "file:///c:/windows/My%20Documents%20100%20/foo.txt"
- #
- # Addressable::URI.convert_path("http://example.com/").to_s
- # #=> "http://example.com/"
- def self.convert_path(path)
- # If we were given nil, return nil.
- return nil unless path
- # If a URI object is passed, just return itself.
- return path if path.kind_of?(self)
- unless path.respond_to?(:to_str)
- raise TypeError, "Can't convert #{path.class} into String."
- end
- # Otherwise, convert to a String
- path = path.to_str.strip
-
- path.sub!(/^file:\/?\/?/, EMPTY_STR) if path =~ /^file:\/?\/?/
- path = SLASH + path if path =~ /^([a-zA-Z])[\|:]/
- uri = self.parse(path)
-
- if uri.scheme == nil
- # Adjust windows-style uris
- uri.path.sub!(/^\/?([a-zA-Z])[\|:][\\\/]/) do
- "/#{$1.downcase}:/"
- end
- uri.path.tr!("\\", SLASH)
- if File.exist?(uri.path) &&
- File.stat(uri.path).directory?
- uri.path.chomp!(SLASH)
- uri.path = uri.path + '/'
- end
-
- # If the path is absolute, set the scheme and host.
- if uri.path.start_with?(SLASH)
- uri.scheme = "file"
- uri.host = EMPTY_STR
- end
- uri.normalize!
- end
-
- return uri
- end
-
- ##
- # Joins several URIs together.
- #
- # @param [String, Addressable::URI, #to_str] *uris
- # The URIs to join.
- #
- # @return [Addressable::URI] The joined URI.
- #
- # @example
- # base = "http://example.com/"
- # uri = Addressable::URI.parse("relative/path")
- # Addressable::URI.join(base, uri)
- # #=> #String
- # is passed, the String
must be formatted as a regular
- # expression character class. (Do not include the surrounding square
- # brackets.) For example, "b-zB-Z0-9"
would cause
- # everything but the letters 'b' through 'z' and the numbers '0' through
- # '9' to be percent encoded. If a Regexp
is passed, the
- # value /[^b-zB-Z0-9]/
would have the same effect. A set of
- # useful String
values may be found in the
- # Addressable::URI::CharacterClasses
module. The default
- # value is the reserved plus unreserved character classes specified in
- # RFC 3986.
- #
- # @param [Regexp] upcase_encoded
- # A string of characters that may already be percent encoded, and whose
- # encodings should be upcased. This allows normalization of percent
- # encodings for characters not included in the
- # character_class
.
- #
- # @return [String] The encoded component.
- #
- # @example
- # Addressable::URI.encode_component("simple/example", "b-zB-Z0-9")
- # => "simple%2Fex%61mple"
- # Addressable::URI.encode_component("simple/example", /[^b-zB-Z0-9]/)
- # => "simple%2Fex%61mple"
- # Addressable::URI.encode_component(
- # "simple/example", Addressable::URI::CharacterClasses::UNRESERVED
- # )
- # => "simple%2Fexample"
- def self.encode_component(component, character_class=
- CharacterClasses::RESERVED + CharacterClasses::UNRESERVED,
- upcase_encoded='')
- return nil if component.nil?
-
- begin
- if component.kind_of?(Symbol) ||
- component.kind_of?(Numeric) ||
- component.kind_of?(TrueClass) ||
- component.kind_of?(FalseClass)
- component = component.to_s
- else
- component = component.to_str
- end
- rescue TypeError, NoMethodError
- raise TypeError, "Can't convert #{component.class} into String."
- end if !component.is_a? String
-
- if ![String, Regexp].include?(character_class.class)
- raise TypeError,
- "Expected String or Regexp, got #{character_class.inspect}"
- end
- if character_class.kind_of?(String)
- character_class = /[^#{character_class}]/
- end
- # We can't perform regexps on invalid UTF sequences, but
- # here we need to, so switch to ASCII.
- component = component.dup
- component.force_encoding(Encoding::ASCII_8BIT)
- # Avoiding gsub! because there are edge cases with frozen strings
- component = component.gsub(character_class) do |char|
- SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE[char.ord]
- end
- if upcase_encoded.length > 0
- upcase_encoded_chars = upcase_encoded.bytes.map do |byte|
- SEQUENCE_ENCODING_TABLE[byte]
- end
- component = component.gsub(/%(#{upcase_encoded_chars.join('|')})/,
- &:upcase)
- end
-
- return component
- end
-
- class << self
- alias_method :escape_component, :encode_component
- end
-
- ##
- # Unencodes any percent encoded characters within a URI component.
- # This method may be used for unencoding either components or full URIs,
- # however, it is recommended to use the unencode_component
- # alias when unencoding components.
- #
- # @param [String, Addressable::URI, #to_str] uri
- # The URI or component to unencode.
- #
- # @param [Class] return_type
- # The type of object to return.
- # This value may only be set to String
or
- # Addressable::URI
. All other values are invalid. Defaults
- # to String
.
- #
- # @param [String] leave_encoded
- # A string of characters to leave encoded. If a percent encoded character
- # in this list is encountered then it will remain percent encoded.
- #
- # @return [String, Addressable::URI]
- # The unencoded component or URI.
- # The return type is determined by the return_type
- # parameter.
- def self.unencode(uri, return_type=String, leave_encoded='')
- return nil if uri.nil?
-
- begin
- uri = uri.to_str
- rescue NoMethodError, TypeError
- raise TypeError, "Can't convert #{uri.class} into String."
- end if !uri.is_a? String
- if ![String, ::Addressable::URI].include?(return_type)
- raise TypeError,
- "Expected Class (String or Addressable::URI), " +
- "got #{return_type.inspect}"
- end
-
- result = uri.gsub(/%[0-9a-f]{2}/i) do |sequence|
- c = sequence[1..3].to_i(16).chr
- c.force_encoding(sequence.encoding)
- leave_encoded.include?(c) ? sequence : c
- end
-
- result.force_encoding(Encoding::UTF_8)
- if return_type == String
- return result
- elsif return_type == ::Addressable::URI
- return ::Addressable::URI.parse(result)
- end
- end
-
- class << self
- alias_method :unescape, :unencode
- alias_method :unencode_component, :unencode
- alias_method :unescape_component, :unencode
- end
-
-
- ##
- # Normalizes the encoding of a URI component.
- #
- # @param [String, #to_str] component The URI component to encode.
- #
- # @param [String, Regexp] character_class
- # The characters which are not percent encoded. If a String
- # is passed, the String
must be formatted as a regular
- # expression character class. (Do not include the surrounding square
- # brackets.) For example, "b-zB-Z0-9"
would cause
- # everything but the letters 'b' through 'z' and the numbers '0'
- # through '9' to be percent encoded. If a Regexp
is passed,
- # the value /[^b-zB-Z0-9]/
would have the same effect. A
- # set of useful String
values may be found in the
- # Addressable::URI::CharacterClasses
module. The default
- # value is the reserved plus unreserved character classes specified in
- # RFC 3986.
- #
- # @param [String] leave_encoded
- # When character_class
is a String
then
- # leave_encoded
is a string of characters that should remain
- # percent encoded while normalizing the component; if they appear percent
- # encoded in the original component, then they will be upcased ("%2f"
- # normalized to "%2F") but otherwise left alone.
- #
- # @return [String] The normalized component.
- #
- # @example
- # Addressable::URI.normalize_component("simpl%65/%65xampl%65", "b-zB-Z")
- # => "simple%2Fex%61mple"
- # Addressable::URI.normalize_component(
- # "simpl%65/%65xampl%65", /[^b-zB-Z]/
- # )
- # => "simple%2Fex%61mple"
- # Addressable::URI.normalize_component(
- # "simpl%65/%65xampl%65",
- # Addressable::URI::CharacterClasses::UNRESERVED
- # )
- # => "simple%2Fexample"
- # Addressable::URI.normalize_component(
- # "one%20two%2fthree%26four",
- # "0-9a-zA-Z &/",
- # "/"
- # )
- # => "one two%2Fthree&four"
- def self.normalize_component(component, character_class=
- CharacterClasses::RESERVED + CharacterClasses::UNRESERVED,
- leave_encoded='')
- return nil if component.nil?
-
- begin
- component = component.to_str
- rescue NoMethodError, TypeError
- raise TypeError, "Can't convert #{component.class} into String."
- end if !component.is_a? String
-
- if ![String, Regexp].include?(character_class.class)
- raise TypeError,
- "Expected String or Regexp, got #{character_class.inspect}"
- end
- if character_class.kind_of?(String)
- leave_re = if leave_encoded.length > 0
- character_class = "#{character_class}%" unless character_class.include?('%')
-
- bytes = leave_encoded.bytes
- leave_encoded_pattern = bytes.map { |b| SEQUENCE_ENCODING_TABLE[b] }.join('|')
- "|%(?!#{leave_encoded_pattern}|#{leave_encoded_pattern.upcase})"
- end
-
- character_class = if leave_re
- /[^#{character_class}]#{leave_re}/
- else
- /[^#{character_class}]/
- end
- end
- # We can't perform regexps on invalid UTF sequences, but
- # here we need to, so switch to ASCII.
- component = component.dup
- component.force_encoding(Encoding::ASCII_8BIT)
- unencoded = self.unencode_component(component, String, leave_encoded)
- begin
- encoded = self.encode_component(
- unencoded.unicode_normalize(:nfc),
- character_class,
- leave_encoded
- )
- rescue ArgumentError
- encoded = self.encode_component(unencoded)
- end
- encoded.force_encoding(Encoding::UTF_8)
- return encoded
- end
-
- ##
- # Percent encodes any special characters in the URI.
- #
- # @param [String, Addressable::URI, #to_str] uri
- # The URI to encode.
- #
- # @param [Class] return_type
- # The type of object to return.
- # This value may only be set to String
or
- # Addressable::URI
. All other values are invalid. Defaults
- # to String
.
- #
- # @return [String, Addressable::URI]
- # The encoded URI.
- # The return type is determined by the return_type
- # parameter.
- def self.encode(uri, return_type=String)
- return nil if uri.nil?
-
- begin
- uri = uri.to_str
- rescue NoMethodError, TypeError
- raise TypeError, "Can't convert #{uri.class} into String."
- end if !uri.is_a? String
-
- if ![String, ::Addressable::URI].include?(return_type)
- raise TypeError,
- "Expected Class (String or Addressable::URI), " +
- "got #{return_type.inspect}"
- end
- uri_object = uri.kind_of?(self) ? uri : self.parse(uri)
- encoded_uri = Addressable::URI.new(
- :scheme => self.encode_component(uri_object.scheme,
- Addressable::URI::CharacterClasses::SCHEME),
- :authority => self.encode_component(uri_object.authority,
- Addressable::URI::CharacterClasses::AUTHORITY),
- :path => self.encode_component(uri_object.path,
- Addressable::URI::CharacterClasses::PATH),
- :query => self.encode_component(uri_object.query,
- Addressable::URI::CharacterClasses::QUERY),
- :fragment => self.encode_component(uri_object.fragment,
- Addressable::URI::CharacterClasses::FRAGMENT)
- )
- if return_type == String
- return encoded_uri.to_s
- elsif return_type == ::Addressable::URI
- return encoded_uri
- end
- end
-
- class << self
- alias_method :escape, :encode
- end
-
- ##
- # Normalizes the encoding of a URI. Characters within a hostname are
- # not percent encoded to allow for internationalized domain names.
- #
- # @param [String, Addressable::URI, #to_str] uri
- # The URI to encode.
- #
- # @param [Class] return_type
- # The type of object to return.
- # This value may only be set to String
or
- # Addressable::URI
. All other values are invalid. Defaults
- # to String
.
- #
- # @return [String, Addressable::URI]
- # The encoded URI.
- # The return type is determined by the return_type
- # parameter.
- def self.normalized_encode(uri, return_type=String)
- begin
- uri = uri.to_str
- rescue NoMethodError, TypeError
- raise TypeError, "Can't convert #{uri.class} into String."
- end if !uri.is_a? String
-
- if ![String, ::Addressable::URI].include?(return_type)
- raise TypeError,
- "Expected Class (String or Addressable::URI), " +
- "got #{return_type.inspect}"
- end
- uri_object = uri.kind_of?(self) ? uri : self.parse(uri)
- components = {
- :scheme => self.unencode_component(uri_object.scheme),
- :user => self.unencode_component(uri_object.user),
- :password => self.unencode_component(uri_object.password),
- :host => self.unencode_component(uri_object.host),
- :port => (uri_object.port.nil? ? nil : uri_object.port.to_s),
- :path => self.unencode_component(uri_object.path),
- :query => self.unencode_component(uri_object.query),
- :fragment => self.unencode_component(uri_object.fragment)
- }
- components.each do |key, value|
- if value != nil
- begin
- components[key] = value.to_str.unicode_normalize(:nfc)
- rescue ArgumentError
- # Likely a malformed UTF-8 character, skip unicode normalization
- components[key] = value.to_str
- end
- end
- end
- encoded_uri = Addressable::URI.new(
- :scheme => self.encode_component(components[:scheme],
- Addressable::URI::CharacterClasses::SCHEME),
- :user => self.encode_component(components[:user],
- Addressable::URI::CharacterClasses::UNRESERVED),
- :password => self.encode_component(components[:password],
- Addressable::URI::CharacterClasses::UNRESERVED),
- :host => components[:host],
- :port => components[:port],
- :path => self.encode_component(components[:path],
- Addressable::URI::CharacterClasses::PATH),
- :query => self.encode_component(components[:query],
- Addressable::URI::CharacterClasses::QUERY),
- :fragment => self.encode_component(components[:fragment],
- Addressable::URI::CharacterClasses::FRAGMENT)
- )
- if return_type == String
- return encoded_uri.to_s
- elsif return_type == ::Addressable::URI
- return encoded_uri
- end
- end
-
- ##
- # Encodes a set of key/value pairs according to the rules for the
- # application/x-www-form-urlencoded
MIME type.
- #
- # @param [#to_hash, #to_ary] form_values
- # The form values to encode.
- #
- # @param [TrueClass, FalseClass] sort
- # Sort the key/value pairs prior to encoding.
- # Defaults to false
.
- #
- # @return [String]
- # The encoded value.
- def self.form_encode(form_values, sort=false)
- if form_values.respond_to?(:to_hash)
- form_values = form_values.to_hash.to_a
- elsif form_values.respond_to?(:to_ary)
- form_values = form_values.to_ary
- else
- raise TypeError, "Can't convert #{form_values.class} into Array."
- end
-
- form_values = form_values.inject([]) do |accu, (key, value)|
- if value.kind_of?(Array)
- value.each do |v|
- accu << [key.to_s, v.to_s]
- end
- else
- accu << [key.to_s, value.to_s]
- end
- accu
- end
-
- if sort
- # Useful for OAuth and optimizing caching systems
- form_values = form_values.sort
- end
- escaped_form_values = form_values.map do |(key, value)|
- # Line breaks are CRLF pairs
- [
- self.encode_component(
- key.gsub(/(\r\n|\n|\r)/, "\r\n"),
- CharacterClasses::UNRESERVED
- ).gsub("%20", "+"),
- self.encode_component(
- value.gsub(/(\r\n|\n|\r)/, "\r\n"),
- CharacterClasses::UNRESERVED
- ).gsub("%20", "+")
- ]
- end
- return escaped_form_values.map do |(key, value)|
- "#{key}=#{value}"
- end.join("&")
- end
-
- ##
- # Decodes a String
according to the rules for the
- # application/x-www-form-urlencoded
MIME type.
- #
- # @param [String, #to_str] encoded_value
- # The form values to decode.
- #
- # @return [Array]
- # The decoded values.
- # This is not a Hash
because of the possibility for
- # duplicate keys.
- def self.form_unencode(encoded_value)
- if !encoded_value.respond_to?(:to_str)
- raise TypeError, "Can't convert #{encoded_value.class} into String."
- end
- encoded_value = encoded_value.to_str
- split_values = encoded_value.split("&").map do |pair|
- pair.split("=", 2)
- end
- return split_values.map do |(key, value)|
- [
- key ? self.unencode_component(
- key.gsub("+", "%20")).gsub(/(\r\n|\n|\r)/, "\n") : nil,
- value ? (self.unencode_component(
- value.gsub("+", "%20")).gsub(/(\r\n|\n|\r)/, "\n")) : nil
- ]
- end
- end
-
- ##
- # Creates a new uri object from component parts.
- #
- # @option [String, #to_str] scheme The scheme component.
- # @option [String, #to_str] user The user component.
- # @option [String, #to_str] password The password component.
- # @option [String, #to_str] userinfo
- # The userinfo component. If this is supplied, the user and password
- # components must be omitted.
- # @option [String, #to_str] host The host component.
- # @option [String, #to_str] port The port component.
- # @option [String, #to_str] authority
- # The authority component. If this is supplied, the user, password,
- # userinfo, host, and port components must be omitted.
- # @option [String, #to_str] path The path component.
- # @option [String, #to_str] query The query component.
- # @option [String, #to_str] fragment The fragment component.
- #
- # @return [Addressable::URI] The constructed URI object.
- def initialize(options={})
- if options.has_key?(:authority)
- if (options.keys & [:userinfo, :user, :password, :host, :port]).any?
- raise ArgumentError,
- "Cannot specify both an authority and any of the components " +
- "within the authority."
- end
- end
- if options.has_key?(:userinfo)
- if (options.keys & [:user, :password]).any?
- raise ArgumentError,
- "Cannot specify both a userinfo and either the user or password."
- end
- end
-
- reset_ivs
-
- defer_validation do
- # Bunch of crazy logic required because of the composite components
- # like userinfo and authority.
- self.scheme = options[:scheme] if options[:scheme]
- self.user = options[:user] if options[:user]
- self.password = options[:password] if options[:password]
- self.userinfo = options[:userinfo] if options[:userinfo]
- self.host = options[:host] if options[:host]
- self.port = options[:port] if options[:port]
- self.authority = options[:authority] if options[:authority]
- self.path = options[:path] if options[:path]
- self.query = options[:query] if options[:query]
- self.query_values = options[:query_values] if options[:query_values]
- self.fragment = options[:fragment] if options[:fragment]
- end
-
- to_s # force path validation
- end
-
- ##
- # Freeze URI, initializing instance variables.
- #
- # @return [Addressable::URI] The frozen URI object.
- def freeze
- self.normalized_scheme
- self.normalized_user
- self.normalized_password
- self.normalized_userinfo
- self.normalized_host
- self.normalized_port
- self.normalized_authority
- self.normalized_site
- self.normalized_path
- self.normalized_query
- self.normalized_fragment
- self.hash
- super
- end
-
- ##
- # The scheme component for this URI.
- #
- # @return [String] The scheme component.
- attr_reader :scheme
-
- ##
- # The scheme component for this URI, normalized.
- #
- # @return [String] The scheme component, normalized.
- def normalized_scheme
- return nil unless self.scheme
- if @normalized_scheme == NONE
- @normalized_scheme = if self.scheme =~ /^\s*ssh\+svn\s*$/i
- "svn+ssh".dup
- else
- Addressable::URI.normalize_component(
- self.scheme.strip.downcase,
- Addressable::URI::NormalizeCharacterClasses::SCHEME
- )
- end
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_scheme)
- @normalized_scheme
- end
-
- ##
- # Sets the scheme component for this URI.
- #
- # @param [String, #to_str] new_scheme The new scheme component.
- def scheme=(new_scheme)
- if new_scheme && !new_scheme.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_scheme.class} into String."
- elsif new_scheme
- new_scheme = new_scheme.to_str
- end
- if new_scheme && new_scheme !~ /\A[a-z][a-z0-9\.\+\-]*\z/i
- raise InvalidURIError, "Invalid scheme format: '#{new_scheme}'"
- end
- @scheme = new_scheme
- @scheme = nil if @scheme.to_s.strip.empty?
-
- # Reset dependent values
- @normalized_scheme = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The user component for this URI.
- #
- # @return [String] The user component.
- attr_reader :user
-
- ##
- # The user component for this URI, normalized.
- #
- # @return [String] The user component, normalized.
- def normalized_user
- return nil unless self.user
- return @normalized_user unless @normalized_user == NONE
- @normalized_user = begin
- if normalized_scheme =~ /https?/ && self.user.strip.empty? &&
- (!self.password || self.password.strip.empty?)
- nil
- else
- Addressable::URI.normalize_component(
- self.user.strip,
- Addressable::URI::NormalizeCharacterClasses::UNRESERVED
- )
- end
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_user)
- @normalized_user
- end
-
- ##
- # Sets the user component for this URI.
- #
- # @param [String, #to_str] new_user The new user component.
- def user=(new_user)
- if new_user && !new_user.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_user.class} into String."
- end
- @user = new_user ? new_user.to_str : nil
-
- # You can't have a nil user with a non-nil password
- if password != nil
- @user = EMPTY_STR unless user
- end
-
- # Reset dependent values
- @userinfo = nil
- @normalized_userinfo = NONE
- @authority = nil
- @normalized_user = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The password component for this URI.
- #
- # @return [String] The password component.
- attr_reader :password
-
- ##
- # The password component for this URI, normalized.
- #
- # @return [String] The password component, normalized.
- def normalized_password
- return nil unless self.password
- return @normalized_password unless @normalized_password == NONE
- @normalized_password = begin
- if self.normalized_scheme =~ /https?/ && self.password.strip.empty? &&
- (!self.user || self.user.strip.empty?)
- nil
- else
- Addressable::URI.normalize_component(
- self.password.strip,
- Addressable::URI::NormalizeCharacterClasses::UNRESERVED
- )
- end
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_password)
- @normalized_password
- end
-
- ##
- # Sets the password component for this URI.
- #
- # @param [String, #to_str] new_password The new password component.
- def password=(new_password)
- if new_password && !new_password.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_password.class} into String."
- end
- @password = new_password ? new_password.to_str : nil
-
- # You can't have a nil user with a non-nil password
- if @password != nil
- self.user = EMPTY_STR if user.nil?
- end
-
- # Reset dependent values
- @userinfo = nil
- @normalized_userinfo = NONE
- @authority = nil
- @normalized_password = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The userinfo component for this URI.
- # Combines the user and password components.
- #
- # @return [String] The userinfo component.
- def userinfo
- current_user = self.user
- current_password = self.password
- (current_user || current_password) && @userinfo ||= begin
- if current_user && current_password
- "#{current_user}:#{current_password}"
- elsif current_user && !current_password
- "#{current_user}"
- end
- end
- end
-
- ##
- # The userinfo component for this URI, normalized.
- #
- # @return [String] The userinfo component, normalized.
- def normalized_userinfo
- return nil unless self.userinfo
- return @normalized_userinfo unless @normalized_userinfo == NONE
- @normalized_userinfo = begin
- current_user = self.normalized_user
- current_password = self.normalized_password
- if !current_user && !current_password
- nil
- elsif current_user && current_password
- "#{current_user}:#{current_password}".dup
- elsif current_user && !current_password
- "#{current_user}".dup
- end
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_userinfo)
- @normalized_userinfo
- end
-
- ##
- # Sets the userinfo component for this URI.
- #
- # @param [String, #to_str] new_userinfo The new userinfo component.
- def userinfo=(new_userinfo)
- if new_userinfo && !new_userinfo.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_userinfo.class} into String."
- end
- new_user, new_password = if new_userinfo
- [
- new_userinfo.to_str.strip[/^(.*):/, 1],
- new_userinfo.to_str.strip[/:(.*)$/, 1]
- ]
- else
- [nil, nil]
- end
-
- # Password assigned first to ensure validity in case of nil
- self.password = new_password
- self.user = new_user
-
- # Reset dependent values
- @authority = nil
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The host component for this URI.
- #
- # @return [String] The host component.
- attr_reader :host
-
- ##
- # The host component for this URI, normalized.
- #
- # @return [String] The host component, normalized.
- def normalized_host
- return nil unless self.host
-
- @normalized_host ||= begin
- if !self.host.strip.empty?
- result = ::Addressable::IDNA.to_ascii(
- URI.unencode_component(self.host.strip.downcase)
- )
- if result =~ /[^\.]\.$/
- # Single trailing dots are unnecessary.
- result = result[0...-1]
- end
- result = Addressable::URI.normalize_component(
- result,
- NormalizeCharacterClasses::HOST
- )
- result
- else
- EMPTY_STR.dup
- end
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_host)
- @normalized_host
- end
-
- ##
- # Sets the host component for this URI.
- #
- # @param [String, #to_str] new_host The new host component.
- def host=(new_host)
- if new_host && !new_host.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_host.class} into String."
- end
- @host = new_host ? new_host.to_str : nil
-
- # Reset dependent values
- @authority = nil
- @normalized_host = nil
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # This method is same as URI::Generic#host except
- # brackets for IPv6 (and 'IPvFuture') addresses are removed.
- #
- # @see Addressable::URI#host
- #
- # @return [String] The hostname for this URI.
- def hostname
- v = self.host
- /\A\[(.*)\]\z/ =~ v ? $1 : v
- end
-
- ##
- # This method is same as URI::Generic#host= except
- # the argument can be a bare IPv6 address (or 'IPvFuture').
- #
- # @see Addressable::URI#host=
- #
- # @param [String, #to_str] new_hostname The new hostname for this URI.
- def hostname=(new_hostname)
- if new_hostname &&
- (new_hostname.respond_to?(:ipv4?) || new_hostname.respond_to?(:ipv6?))
- new_hostname = new_hostname.to_s
- elsif new_hostname && !new_hostname.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_hostname.class} into String."
- end
- v = new_hostname ? new_hostname.to_str : nil
- v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v
- self.host = v
- end
-
- ##
- # Returns the top-level domain for this host.
- #
- # @example
- # Addressable::URI.parse("http://www.example.co.uk").tld # => "co.uk"
- def tld
- PublicSuffix.parse(self.host, ignore_private: true).tld
- end
-
- ##
- # Sets the top-level domain for this URI.
- #
- # @param [String, #to_str] new_tld The new top-level domain.
- def tld=(new_tld)
- replaced_tld = host.sub(/#{tld}\z/, new_tld)
- self.host = PublicSuffix::Domain.new(replaced_tld).to_s
- end
-
- ##
- # Returns the public suffix domain for this host.
- #
- # @example
- # Addressable::URI.parse("http://www.example.co.uk").domain # => "example.co.uk"
- def domain
- PublicSuffix.domain(self.host, ignore_private: true)
- end
-
- ##
- # The authority component for this URI.
- # Combines the user, password, host, and port components.
- #
- # @return [String] The authority component.
- def authority
- self.host && @authority ||= begin
- authority = String.new
- if self.userinfo != nil
- authority << "#{self.userinfo}@"
- end
- authority << self.host
- if self.port != nil
- authority << ":#{self.port}"
- end
- authority
- end
- end
-
- ##
- # The authority component for this URI, normalized.
- #
- # @return [String] The authority component, normalized.
- def normalized_authority
- return nil unless self.authority
- @normalized_authority ||= begin
- authority = String.new
- if self.normalized_userinfo != nil
- authority << "#{self.normalized_userinfo}@"
- end
- authority << self.normalized_host
- if self.normalized_port != nil
- authority << ":#{self.normalized_port}"
- end
- authority
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_authority)
- @normalized_authority
- end
-
- ##
- # Sets the authority component for this URI.
- #
- # @param [String, #to_str] new_authority The new authority component.
- def authority=(new_authority)
- if new_authority
- if !new_authority.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_authority.class} into String."
- end
- new_authority = new_authority.to_str
- new_userinfo = new_authority[/^([^\[\]]*)@/, 1]
- if new_userinfo
- new_user = new_userinfo.strip[/^([^:]*):?/, 1]
- new_password = new_userinfo.strip[/:(.*)$/, 1]
- end
- new_host = new_authority.sub(
- /^([^\[\]]*)@/, EMPTY_STR
- ).sub(
- /:([^:@\[\]]*?)$/, EMPTY_STR
- )
- new_port =
- new_authority[/:([^:@\[\]]*?)$/, 1]
- end
-
- # Password assigned first to ensure validity in case of nil
- self.password = new_password
- self.user = new_user
- self.host = new_host
- self.port = new_port
-
- # Reset dependent values
- @userinfo = nil
- @normalized_userinfo = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The origin for this URI, serialized to ASCII, as per
- # RFC 6454, section 6.2.
- #
- # @return [String] The serialized origin.
- def origin
- if self.scheme && self.authority
- if self.normalized_port
- "#{self.normalized_scheme}://#{self.normalized_host}" +
- ":#{self.normalized_port}"
- else
- "#{self.normalized_scheme}://#{self.normalized_host}"
- end
- else
- "null"
- end
- end
-
- ##
- # Sets the origin for this URI, serialized to ASCII, as per
- # RFC 6454, section 6.2. This assignment will reset the `userinfo`
- # component.
- #
- # @param [String, #to_str] new_origin The new origin component.
- def origin=(new_origin)
- if new_origin
- if !new_origin.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_origin.class} into String."
- end
- new_origin = new_origin.to_str
- new_scheme = new_origin[/^([^:\/?#]+):\/\//, 1]
- unless new_scheme
- raise InvalidURIError, 'An origin cannot omit the scheme.'
- end
- new_host = new_origin[/:\/\/([^\/?#:]+)/, 1]
- unless new_host
- raise InvalidURIError, 'An origin cannot omit the host.'
- end
- new_port = new_origin[/:([^:@\[\]\/]*?)$/, 1]
- end
-
- self.scheme = new_scheme
- self.host = new_host
- self.port = new_port
- self.userinfo = nil
-
- # Reset dependent values
- @userinfo = nil
- @normalized_userinfo = NONE
- @authority = nil
- @normalized_authority = nil
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- # Returns an array of known ip-based schemes. These schemes typically
- # use a similar URI form:
- # //:@:/
- def self.ip_based_schemes
- return self.port_mapping.keys
- end
-
- # Returns a hash of common IP-based schemes and their default port
- # numbers. Adding new schemes to this hash, as necessary, will allow
- # for better URI normalization.
- def self.port_mapping
- PORT_MAPPING
- end
-
- ##
- # The port component for this URI.
- # This is the port number actually given in the URI. This does not
- # infer port numbers from default values.
- #
- # @return [Integer] The port component.
- attr_reader :port
-
- ##
- # The port component for this URI, normalized.
- #
- # @return [Integer] The port component, normalized.
- def normalized_port
- return nil unless self.port
- return @normalized_port unless @normalized_port == NONE
- @normalized_port = begin
- if URI.port_mapping[self.normalized_scheme] == self.port
- nil
- else
- self.port
- end
- end
- end
-
- ##
- # Sets the port component for this URI.
- #
- # @param [String, Integer, #to_s] new_port The new port component.
- def port=(new_port)
- if new_port != nil && new_port.respond_to?(:to_str)
- new_port = Addressable::URI.unencode_component(new_port.to_str)
- end
-
- if new_port.respond_to?(:valid_encoding?) && !new_port.valid_encoding?
- raise InvalidURIError, "Invalid encoding in port"
- end
-
- if new_port != nil && !(new_port.to_s =~ /^\d+$/)
- raise InvalidURIError,
- "Invalid port number: #{new_port.inspect}"
- end
-
- @port = new_port.to_s.to_i
- @port = nil if @port == 0
-
- # Reset dependent values
- @authority = nil
- @normalized_port = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The inferred port component for this URI.
- # This method will normalize to the default port for the URI's scheme if
- # the port isn't explicitly specified in the URI.
- #
- # @return [Integer] The inferred port component.
- def inferred_port
- if self.port.to_i == 0
- self.default_port
- else
- self.port.to_i
- end
- end
-
- ##
- # The default port for this URI's scheme.
- # This method will always returns the default port for the URI's scheme
- # regardless of the presence of an explicit port in the URI.
- #
- # @return [Integer] The default port.
- def default_port
- URI.port_mapping[self.scheme.strip.downcase] if self.scheme
- end
-
- ##
- # The combination of components that represent a site.
- # Combines the scheme, user, password, host, and port components.
- # Primarily useful for HTTP and HTTPS.
- #
- # For example, "http://example.com/path?query"
would have a
- # site
value of "http://example.com"
.
- #
- # @return [String] The components that identify a site.
- def site
- (self.scheme || self.authority) && @site ||= begin
- site_string = "".dup
- site_string << "#{self.scheme}:" if self.scheme != nil
- site_string << "//#{self.authority}" if self.authority != nil
- site_string
- end
- end
-
- ##
- # The normalized combination of components that represent a site.
- # Combines the scheme, user, password, host, and port components.
- # Primarily useful for HTTP and HTTPS.
- #
- # For example, "http://example.com/path?query"
would have a
- # site
value of "http://example.com"
.
- #
- # @return [String] The normalized components that identify a site.
- def normalized_site
- return nil unless self.site
- @normalized_site ||= begin
- site_string = "".dup
- if self.normalized_scheme != nil
- site_string << "#{self.normalized_scheme}:"
- end
- if self.normalized_authority != nil
- site_string << "//#{self.normalized_authority}"
- end
- site_string
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_site)
- @normalized_site
- end
-
- ##
- # Sets the site value for this URI.
- #
- # @param [String, #to_str] new_site The new site value.
- def site=(new_site)
- if new_site
- if !new_site.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_site.class} into String."
- end
- new_site = new_site.to_str
- # These two regular expressions derived from the primary parsing
- # expression
- self.scheme = new_site[/^(?:([^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?$/, 1]
- self.authority = new_site[
- /^(?:(?:[^:\/?#]+):)?(?:\/\/([^\/?#]*))?$/, 1
- ]
- else
- self.scheme = nil
- self.authority = nil
- end
- end
-
- ##
- # The path component for this URI.
- #
- # @return [String] The path component.
- attr_reader :path
-
- NORMPATH = /^(?!\/)[^\/:]*:.*$/
- ##
- # The path component for this URI, normalized.
- #
- # @return [String] The path component, normalized.
- def normalized_path
- @normalized_path ||= begin
- path = self.path.to_s
- if self.scheme == nil && path =~ NORMPATH
- # Relative paths with colons in the first segment are ambiguous.
- path = path.sub(":", "%2F")
- end
- # String#split(delimeter, -1) uses the more strict splitting behavior
- # found by default in Python.
- result = path.strip.split(SLASH, -1).map do |segment|
- Addressable::URI.normalize_component(
- segment,
- Addressable::URI::NormalizeCharacterClasses::PCHAR
- )
- end.join(SLASH)
-
- result = URI.normalize_path(result)
- if result.empty? &&
- ["http", "https", "ftp", "tftp"].include?(self.normalized_scheme)
- result = SLASH.dup
- end
- result
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_path)
- @normalized_path
- end
-
- ##
- # Sets the path component for this URI.
- #
- # @param [String, #to_str] new_path The new path component.
- def path=(new_path)
- if new_path && !new_path.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_path.class} into String."
- end
- @path = (new_path || EMPTY_STR).to_str
- if !@path.empty? && @path[0..0] != SLASH && host != nil
- @path = "/#{@path}"
- end
-
- # Reset dependent values
- @normalized_path = nil
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # The basename, if any, of the file in the path component.
- #
- # @return [String] The path's basename.
- def basename
- # Path cannot be nil
- return File.basename(self.path).sub(/;[^\/]*$/, EMPTY_STR)
- end
-
- ##
- # The extname, if any, of the file in the path component.
- # Empty string if there is no extension.
- #
- # @return [String] The path's extname.
- def extname
- return nil unless self.path
- return File.extname(self.basename)
- end
-
- ##
- # The query component for this URI.
- #
- # @return [String] The query component.
- attr_reader :query
-
- ##
- # The query component for this URI, normalized.
- #
- # @return [String] The query component, normalized.
- def normalized_query(*flags)
- return nil unless self.query
- return @normalized_query unless @normalized_query == NONE
- @normalized_query = begin
- modified_query_class = Addressable::URI::CharacterClasses::QUERY.dup
- # Make sure possible key-value pair delimiters are escaped.
- modified_query_class.sub!("\\&", "").sub!("\\;", "")
- pairs = (query || "").split("&", -1)
- pairs.delete_if(&:empty?).uniq! if flags.include?(:compacted)
- pairs.sort! if flags.include?(:sorted)
- component = pairs.map do |pair|
- Addressable::URI.normalize_component(
- pair,
- Addressable::URI::NormalizeCharacterClasses::QUERY,
- "+"
- )
- end.join("&")
- component == "" ? nil : component
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_query)
- @normalized_query
- end
-
- ##
- # Sets the query component for this URI.
- #
- # @param [String, #to_str] new_query The new query component.
- def query=(new_query)
- if new_query && !new_query.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_query.class} into String."
- end
- @query = new_query ? new_query.to_str : nil
-
- # Reset dependent values
- @normalized_query = NONE
- remove_composite_values
- end
-
- ##
- # Converts the query component to a Hash value.
- #
- # @param [Class] return_type The return type desired. Value must be either
- # `Hash` or `Array`.
- #
- # @return [Hash, Array, nil] The query string parsed as a Hash or Array
- # or nil if the query string is blank.
- #
- # @example
- # Addressable::URI.parse("?one=1&two=2&three=3").query_values
- # #=> {"one" => "1", "two" => "2", "three" => "3"}
- # Addressable::URI.parse("?one=two&one=three").query_values(Array)
- # #=> [["one", "two"], ["one", "three"]]
- # Addressable::URI.parse("?one=two&one=three").query_values(Hash)
- # #=> {"one" => "three"}
- # Addressable::URI.parse("?").query_values
- # #=> {}
- # Addressable::URI.parse("").query_values
- # #=> nil
- def query_values(return_type=Hash)
- empty_accumulator = Array == return_type ? [] : {}
- if return_type != Hash && return_type != Array
- raise ArgumentError, "Invalid return type. Must be Hash or Array."
- end
- return nil if self.query == nil
- split_query = self.query.split("&").map do |pair|
- pair.split("=", 2) if pair && !pair.empty?
- end.compact
- return split_query.inject(empty_accumulator.dup) do |accu, pair|
- # I'd rather use key/value identifiers instead of array lookups,
- # but in this case I really want to maintain the exact pair structure,
- # so it's best to make all changes in-place.
- pair[0] = URI.unencode_component(pair[0])
- if pair[1].respond_to?(:to_str)
- value = pair[1].to_str
- # I loathe the fact that I have to do this. Stupid HTML 4.01.
- # Treating '+' as a space was just an unbelievably bad idea.
- # There was nothing wrong with '%20'!
- # If it ain't broke, don't fix it!
- value = value.tr("+", " ") if ["http", "https", nil].include?(scheme)
- pair[1] = URI.unencode_component(value)
- end
- if return_type == Hash
- accu[pair[0]] = pair[1]
- else
- accu << pair
- end
- accu
- end
- end
-
- ##
- # Sets the query component for this URI from a Hash object.
- # An empty Hash or Array will result in an empty query string.
- #
- # @param [Hash, #to_hash, Array] new_query_values The new query values.
- #
- # @example
- # uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
- # uri.query
- # # => "a=a&b=c&b=d&b=e"
- # uri.query_values = [['a', 'a'], ['b', 'c'], ['b', 'd'], ['b', 'e']]
- # uri.query
- # # => "a=a&b=c&b=d&b=e"
- # uri.query_values = [['a', 'a'], ['b', ['c', 'd', 'e']]]
- # uri.query
- # # => "a=a&b=c&b=d&b=e"
- # uri.query_values = [['flag'], ['key', 'value']]
- # uri.query
- # # => "flag&key=value"
- def query_values=(new_query_values)
- if new_query_values == nil
- self.query = nil
- return nil
- end
-
- if !new_query_values.is_a?(Array)
- if !new_query_values.respond_to?(:to_hash)
- raise TypeError,
- "Can't convert #{new_query_values.class} into Hash."
- end
- new_query_values = new_query_values.to_hash
- new_query_values = new_query_values.map do |key, value|
- key = key.to_s if key.kind_of?(Symbol)
- [key, value]
- end
- # Useful default for OAuth and caching.
- # Only to be used for non-Array inputs. Arrays should preserve order.
- new_query_values.sort!
- end
-
- # new_query_values have form [['key1', 'value1'], ['key2', 'value2']]
- buffer = "".dup
- new_query_values.each do |key, value|
- encoded_key = URI.encode_component(
- key, CharacterClasses::UNRESERVED
- )
- if value == nil
- buffer << "#{encoded_key}&"
- elsif value.kind_of?(Array)
- value.each do |sub_value|
- encoded_value = URI.encode_component(
- sub_value, CharacterClasses::UNRESERVED
- )
- buffer << "#{encoded_key}=#{encoded_value}&"
- end
- else
- encoded_value = URI.encode_component(
- value, CharacterClasses::UNRESERVED
- )
- buffer << "#{encoded_key}=#{encoded_value}&"
- end
- end
- self.query = buffer.chop
- end
-
- ##
- # The HTTP request URI for this URI. This is the path and the
- # query string.
- #
- # @return [String] The request URI required for an HTTP request.
- def request_uri
- return nil if self.absolute? && self.scheme !~ /^https?$/i
- return (
- (!self.path.empty? ? self.path : SLASH) +
- (self.query ? "?#{self.query}" : EMPTY_STR)
- )
- end
-
- ##
- # Sets the HTTP request URI for this URI.
- #
- # @param [String, #to_str] new_request_uri The new HTTP request URI.
- def request_uri=(new_request_uri)
- if !new_request_uri.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_request_uri.class} into String."
- end
- if self.absolute? && self.scheme !~ /^https?$/i
- raise InvalidURIError,
- "Cannot set an HTTP request URI for a non-HTTP URI."
- end
- new_request_uri = new_request_uri.to_str
- path_component = new_request_uri[/^([^\?]*)\??(?:.*)$/, 1]
- query_component = new_request_uri[/^(?:[^\?]*)\?(.*)$/, 1]
- path_component = path_component.to_s
- path_component = (!path_component.empty? ? path_component : SLASH)
- self.path = path_component
- self.query = query_component
-
- # Reset dependent values
- remove_composite_values
- end
-
- ##
- # The fragment component for this URI.
- #
- # @return [String] The fragment component.
- attr_reader :fragment
-
- ##
- # The fragment component for this URI, normalized.
- #
- # @return [String] The fragment component, normalized.
- def normalized_fragment
- return nil unless self.fragment
- return @normalized_fragment unless @normalized_fragment == NONE
- @normalized_fragment = begin
- component = Addressable::URI.normalize_component(
- self.fragment,
- Addressable::URI::NormalizeCharacterClasses::FRAGMENT
- )
- component == "" ? nil : component
- end
- # All normalized values should be UTF-8
- force_utf8_encoding_if_needed(@normalized_fragment)
- @normalized_fragment
- end
-
- ##
- # Sets the fragment component for this URI.
- #
- # @param [String, #to_str] new_fragment The new fragment component.
- def fragment=(new_fragment)
- if new_fragment && !new_fragment.respond_to?(:to_str)
- raise TypeError, "Can't convert #{new_fragment.class} into String."
- end
- @fragment = new_fragment ? new_fragment.to_str : nil
-
- # Reset dependent values
- @normalized_fragment = NONE
- remove_composite_values
-
- # Ensure we haven't created an invalid URI
- validate()
- end
-
- ##
- # Determines if the scheme indicates an IP-based protocol.
- #
- # @return [TrueClass, FalseClass]
- # true
if the scheme indicates an IP-based protocol.
- # false
otherwise.
- def ip_based?
- if self.scheme
- return URI.ip_based_schemes.include?(
- self.scheme.strip.downcase)
- end
- return false
- end
-
- ##
- # Determines if the URI is relative.
- #
- # @return [TrueClass, FalseClass]
- # true
if the URI is relative. false
- # otherwise.
- def relative?
- return self.scheme.nil?
- end
-
- ##
- # Determines if the URI is absolute.
- #
- # @return [TrueClass, FalseClass]
- # true
if the URI is absolute. false
- # otherwise.
- def absolute?
- return !relative?
- end
-
- ##
- # Joins two URIs together.
- #
- # @param [String, Addressable::URI, #to_str] The URI to join with.
- #
- # @return [Addressable::URI] The joined URI.
- def join(uri)
- if !uri.respond_to?(:to_str)
- raise TypeError, "Can't convert #{uri.class} into String."
- end
- if !uri.kind_of?(URI)
- # Otherwise, convert to a String, then parse.
- uri = URI.parse(uri.to_str)
- end
- if uri.to_s.empty?
- return self.dup
- end
-
- joined_scheme = nil
- joined_user = nil
- joined_password = nil
- joined_host = nil
- joined_port = nil
- joined_path = nil
- joined_query = nil
- joined_fragment = nil
-
- # Section 5.2.2 of RFC 3986
- if uri.scheme != nil
- joined_scheme = uri.scheme
- joined_user = uri.user
- joined_password = uri.password
- joined_host = uri.host
- joined_port = uri.port
- joined_path = URI.normalize_path(uri.path)
- joined_query = uri.query
- else
- if uri.authority != nil
- joined_user = uri.user
- joined_password = uri.password
- joined_host = uri.host
- joined_port = uri.port
- joined_path = URI.normalize_path(uri.path)
- joined_query = uri.query
- else
- if uri.path == nil || uri.path.empty?
- joined_path = self.path
- if uri.query != nil
- joined_query = uri.query
- else
- joined_query = self.query
- end
- else
- if uri.path[0..0] == SLASH
- joined_path = URI.normalize_path(uri.path)
- else
- base_path = self.path.dup
- base_path = EMPTY_STR if base_path == nil
- base_path = URI.normalize_path(base_path)
-
- # Section 5.2.3 of RFC 3986
- #
- # Removes the right-most path segment from the base path.
- if base_path.include?(SLASH)
- base_path.sub!(/\/[^\/]+$/, SLASH)
- else
- base_path = EMPTY_STR
- end
-
- # If the base path is empty and an authority segment has been
- # defined, use a base path of SLASH
- if base_path.empty? && self.authority != nil
- base_path = SLASH
- end
-
- joined_path = URI.normalize_path(base_path + uri.path)
- end
- joined_query = uri.query
- end
- joined_user = self.user
- joined_password = self.password
- joined_host = self.host
- joined_port = self.port
- end
- joined_scheme = self.scheme
- end
- joined_fragment = uri.fragment
-
- return self.class.new(
- :scheme => joined_scheme,
- :user => joined_user,
- :password => joined_password,
- :host => joined_host,
- :port => joined_port,
- :path => joined_path,
- :query => joined_query,
- :fragment => joined_fragment
- )
- end
- alias_method :+, :join
-
- ##
- # Destructive form of join
.
- #
- # @param [String, Addressable::URI, #to_str] The URI to join with.
- #
- # @return [Addressable::URI] The joined URI.
- #
- # @see Addressable::URI#join
- def join!(uri)
- replace_self(self.join(uri))
- end
-
- ##
- # Merges a URI with a Hash
of components.
- # This method has different behavior from join
. Any
- # components present in the hash
parameter will override the
- # original components. The path component is not treated specially.
- #
- # @param [Hash, Addressable::URI, #to_hash] The components to merge with.
- #
- # @return [Addressable::URI] The merged URI.
- #
- # @see Hash#merge
- def merge(hash)
- unless hash.respond_to?(:to_hash)
- raise TypeError, "Can't convert #{hash.class} into Hash."
- end
- hash = hash.to_hash
-
- if hash.has_key?(:authority)
- if (hash.keys & [:userinfo, :user, :password, :host, :port]).any?
- raise ArgumentError,
- "Cannot specify both an authority and any of the components " +
- "within the authority."
- end
- end
- if hash.has_key?(:userinfo)
- if (hash.keys & [:user, :password]).any?
- raise ArgumentError,
- "Cannot specify both a userinfo and either the user or password."
- end
- end
-
- uri = self.class.new
- uri.defer_validation do
- # Bunch of crazy logic required because of the composite components
- # like userinfo and authority.
- uri.scheme =
- hash.has_key?(:scheme) ? hash[:scheme] : self.scheme
- if hash.has_key?(:authority)
- uri.authority =
- hash.has_key?(:authority) ? hash[:authority] : self.authority
- end
- if hash.has_key?(:userinfo)
- uri.userinfo =
- hash.has_key?(:userinfo) ? hash[:userinfo] : self.userinfo
- end
- if !hash.has_key?(:userinfo) && !hash.has_key?(:authority)
- uri.user =
- hash.has_key?(:user) ? hash[:user] : self.user
- uri.password =
- hash.has_key?(:password) ? hash[:password] : self.password
- end
- if !hash.has_key?(:authority)
- uri.host =
- hash.has_key?(:host) ? hash[:host] : self.host
- uri.port =
- hash.has_key?(:port) ? hash[:port] : self.port
- end
- uri.path =
- hash.has_key?(:path) ? hash[:path] : self.path
- uri.query =
- hash.has_key?(:query) ? hash[:query] : self.query
- uri.fragment =
- hash.has_key?(:fragment) ? hash[:fragment] : self.fragment
- end
-
- return uri
- end
-
- ##
- # Destructive form of merge
.
- #
- # @param [Hash, Addressable::URI, #to_hash] The components to merge with.
- #
- # @return [Addressable::URI] The merged URI.
- #
- # @see Addressable::URI#merge
- def merge!(uri)
- replace_self(self.merge(uri))
- end
-
- ##
- # Returns the shortest normalized relative form of this URI that uses the
- # supplied URI as a base for resolution. Returns an absolute URI if
- # necessary. This is effectively the opposite of route_to
.
- #
- # @param [String, Addressable::URI, #to_str] uri The URI to route from.
- #
- # @return [Addressable::URI]
- # The normalized relative URI that is equivalent to the original URI.
- def route_from(uri)
- uri = URI.parse(uri).normalize
- normalized_self = self.normalize
- if normalized_self.relative?
- raise ArgumentError, "Expected absolute URI, got: #{self.to_s}"
- end
- if uri.relative?
- raise ArgumentError, "Expected absolute URI, got: #{uri.to_s}"
- end
- if normalized_self == uri
- return Addressable::URI.parse("##{normalized_self.fragment}")
- end
- components = normalized_self.to_hash
- if normalized_self.scheme == uri.scheme
- components[:scheme] = nil
- if normalized_self.authority == uri.authority
- components[:user] = nil
- components[:password] = nil
- components[:host] = nil
- components[:port] = nil
- if normalized_self.path == uri.path
- components[:path] = nil
- if normalized_self.query == uri.query
- components[:query] = nil
- end
- else
- if uri.path != SLASH and components[:path]
- self_splitted_path = split_path(components[:path])
- uri_splitted_path = split_path(uri.path)
- self_dir = self_splitted_path.shift
- uri_dir = uri_splitted_path.shift
- while !self_splitted_path.empty? && !uri_splitted_path.empty? and self_dir == uri_dir
- self_dir = self_splitted_path.shift
- uri_dir = uri_splitted_path.shift
- end
- components[:path] = (uri_splitted_path.fill('..') + [self_dir] + self_splitted_path).join(SLASH)
- end
- end
- end
- end
- # Avoid network-path references.
- if components[:host] != nil
- components[:scheme] = normalized_self.scheme
- end
- return Addressable::URI.new(
- :scheme => components[:scheme],
- :user => components[:user],
- :password => components[:password],
- :host => components[:host],
- :port => components[:port],
- :path => components[:path],
- :query => components[:query],
- :fragment => components[:fragment]
- )
- end
-
- ##
- # Returns the shortest normalized relative form of the supplied URI that
- # uses this URI as a base for resolution. Returns an absolute URI if
- # necessary. This is effectively the opposite of route_from
.
- #
- # @param [String, Addressable::URI, #to_str] uri The URI to route to.
- #
- # @return [Addressable::URI]
- # The normalized relative URI that is equivalent to the supplied URI.
- def route_to(uri)
- return URI.parse(uri).route_from(self)
- end
-
- ##
- # Returns a normalized URI object.
- #
- # NOTE: This method does not attempt to fully conform to specifications.
- # It exists largely to correct other people's failures to read the
- # specifications, and also to deal with caching issues since several
- # different URIs may represent the same resource and should not be
- # cached multiple times.
- #
- # @return [Addressable::URI] The normalized URI.
- def normalize
- # This is a special exception for the frequently misused feed
- # URI scheme.
- if normalized_scheme == "feed"
- if self.to_s =~ /^feed:\/*http:\/*/
- return URI.parse(
- self.to_s[/^feed:\/*(http:\/*.*)/, 1]
- ).normalize
- end
- end
-
- return self.class.new(
- :scheme => normalized_scheme,
- :authority => normalized_authority,
- :path => normalized_path,
- :query => normalized_query,
- :fragment => normalized_fragment
- )
- end
-
- ##
- # Destructively normalizes this URI object.
- #
- # @return [Addressable::URI] The normalized URI.
- #
- # @see Addressable::URI#normalize
- def normalize!
- replace_self(self.normalize)
- end
-
- ##
- # Creates a URI suitable for display to users. If semantic attacks are
- # likely, the application should try to detect these and warn the user.
- # See RFC 3986,
- # section 7.6 for more information.
- #
- # @return [Addressable::URI] A URI suitable for display purposes.
- def display_uri
- display_uri = self.normalize
- display_uri.host = ::Addressable::IDNA.to_unicode(display_uri.host)
- return display_uri
- end
-
- ##
- # Returns true
if the URI objects are equal. This method
- # normalizes both URIs before doing the comparison, and allows comparison
- # against Strings
.
- #
- # @param [Object] uri The URI to compare.
- #
- # @return [TrueClass, FalseClass]
- # true
if the URIs are equivalent, false
- # otherwise.
- def ===(uri)
- if uri.respond_to?(:normalize)
- uri_string = uri.normalize.to_s
- else
- begin
- uri_string = ::Addressable::URI.parse(uri).normalize.to_s
- rescue InvalidURIError, TypeError
- return false
- end
- end
- return self.normalize.to_s == uri_string
- end
-
- ##
- # Returns true
if the URI objects are equal. This method
- # normalizes both URIs before doing the comparison.
- #
- # @param [Object] uri The URI to compare.
- #
- # @return [TrueClass, FalseClass]
- # true
if the URIs are equivalent, false
- # otherwise.
- def ==(uri)
- return false unless uri.kind_of?(URI)
- return self.normalize.to_s == uri.normalize.to_s
- end
-
- ##
- # Returns true
if the URI objects are equal. This method
- # does NOT normalize either URI before doing the comparison.
- #
- # @param [Object] uri The URI to compare.
- #
- # @return [TrueClass, FalseClass]
- # true
if the URIs are equivalent, false
- # otherwise.
- def eql?(uri)
- return false unless uri.kind_of?(URI)
- return self.to_s == uri.to_s
- end
-
- ##
- # A hash value that will make a URI equivalent to its normalized
- # form.
- #
- # @return [Integer] A hash of the URI.
- def hash
- @hash ||= self.to_s.hash * -1
- end
-
- ##
- # Clones the URI object.
- #
- # @return [Addressable::URI] The cloned URI.
- def dup
- duplicated_uri = self.class.new(
- :scheme => self.scheme ? self.scheme.dup : nil,
- :user => self.user ? self.user.dup : nil,
- :password => self.password ? self.password.dup : nil,
- :host => self.host ? self.host.dup : nil,
- :port => self.port,
- :path => self.path ? self.path.dup : nil,
- :query => self.query ? self.query.dup : nil,
- :fragment => self.fragment ? self.fragment.dup : nil
- )
- return duplicated_uri
- end
-
- ##
- # Omits components from a URI.
- #
- # @param [Symbol] *components The components to be omitted.
- #
- # @return [Addressable::URI] The URI with components omitted.
- #
- # @example
- # uri = Addressable::URI.parse("http://example.com/path?query")
- # #=> #true
if empty, false
otherwise.
- def empty?
- return self.to_s.empty?
- end
-
- ##
- # Converts the URI to a String
.
- #
- # @return [String] The URI's String
representation.
- def to_s
- if self.scheme == nil && self.path != nil && !self.path.empty? &&
- self.path =~ NORMPATH
- raise InvalidURIError,
- "Cannot assemble URI string with ambiguous path: '#{self.path}'"
- end
- @uri_string ||= begin
- uri_string = String.new
- uri_string << "#{self.scheme}:" if self.scheme != nil
- uri_string << "//#{self.authority}" if self.authority != nil
- uri_string << self.path.to_s
- uri_string << "?#{self.query}" if self.query != nil
- uri_string << "##{self.fragment}" if self.fragment != nil
- uri_string.force_encoding(Encoding::UTF_8)
- uri_string
- end
- end
-
- ##
- # URI's are glorified Strings
. Allow implicit conversion.
- alias_method :to_str, :to_s
-
- ##
- # Returns a Hash of the URI components.
- #
- # @return [Hash] The URI as a Hash
of components.
- def to_hash
- return {
- :scheme => self.scheme,
- :user => self.user,
- :password => self.password,
- :host => self.host,
- :port => self.port,
- :path => self.path,
- :query => self.query,
- :fragment => self.fragment
- }
- end
-
- ##
- # Returns a String
representation of the URI object's state.
- #
- # @return [String] The URI object's state, as a String
.
- def inspect
- sprintf("#<%s:%#0x URI:%s>", URI.to_s, self.object_id, self.to_s)
- end
-
- ##
- # This method allows you to make several changes to a URI simultaneously,
- # which separately would cause validation errors, but in conjunction,
- # are valid. The URI will be revalidated as soon as the entire block has
- # been executed.
- #
- # @param [Proc] block
- # A set of operations to perform on a given URI.
- def defer_validation
- raise LocalJumpError, "No block given." unless block_given?
- @validation_deferred = true
- yield
- @validation_deferred = false
- validate
- ensure
- @validation_deferred = false
- end
-
- def encode_with(coder)
- instance_variables.each do |ivar|
- value = instance_variable_get(ivar)
- if value != NONE
- key = ivar.to_s.slice(1..-1)
- coder[key] = value
- end
- end
- nil
- end
-
- def init_with(coder)
- reset_ivs
- coder.map.each do |key, value|
- instance_variable_set("@#{key}", value)
- end
- nil
- end
-
- protected
- SELF_REF = '.'
- PARENT = '..'
-
- RULE_2A = /\/\.\/|\/\.$/
- RULE_2B_2C = /\/([^\/]*)\/\.\.\/|\/([^\/]*)\/\.\.$/
- RULE_2D = /^\.\.?\/?/
- RULE_PREFIXED_PARENT = /^\/\.\.?\/|^(\/\.\.?)+\/?$/
-
- ##
- # Resolves paths to their simplest form.
- #
- # @param [String] path The path to normalize.
- #
- # @return [String] The normalized path.
- def self.normalize_path(path)
- # Section 5.2.4 of RFC 3986
-
- return if path.nil?
- normalized_path = path.dup
- loop do
- mod ||= normalized_path.gsub!(RULE_2A, SLASH)
-
- pair = normalized_path.match(RULE_2B_2C)
- if pair
- parent = pair[1]
- current = pair[2]
- else
- parent = nil
- current = nil
- end
-
- regexp = "/#{Regexp.escape(parent.to_s)}/\\.\\./|"
- regexp += "(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
-
- if pair && ((parent != SELF_REF && parent != PARENT) ||
- (current != SELF_REF && current != PARENT))
- mod ||= normalized_path.gsub!(Regexp.new(regexp), SLASH)
- end
-
- mod ||= normalized_path.gsub!(RULE_2D, EMPTY_STR)
- # Non-standard, removes prefixed dotted segments from path.
- mod ||= normalized_path.gsub!(RULE_PREFIXED_PARENT, SLASH)
- break if mod.nil?
- end
-
- normalized_path
- end
-
- ##
- # Ensures that the URI is valid.
- def validate
- return if !!@validation_deferred
- if self.scheme != nil && self.ip_based? &&
- (self.host == nil || self.host.empty?) &&
- (self.path == nil || self.path.empty?)
- raise InvalidURIError,
- "Absolute URI missing hierarchical segment: '#{self.to_s}'"
- end
- if self.host == nil
- if self.port != nil ||
- self.user != nil ||
- self.password != nil
- raise InvalidURIError, "Hostname not supplied: '#{self.to_s}'"
- end
- end
- if self.path != nil && !self.path.empty? && self.path[0..0] != SLASH &&
- self.authority != nil
- raise InvalidURIError,
- "Cannot have a relative path with an authority set: '#{self.to_s}'"
- end
- if self.path != nil && !self.path.empty? &&
- self.path[0..1] == SLASH + SLASH && self.authority == nil
- raise InvalidURIError,
- "Cannot have a path with two leading slashes " +
- "without an authority set: '#{self.to_s}'"
- end
- unreserved = CharacterClasses::UNRESERVED
- sub_delims = CharacterClasses::SUB_DELIMS
- if !self.host.nil? && (self.host =~ /[<>{}\/\\\?\#\@"[[:space:]]]/ ||
- (self.host[/^\[(.*)\]$/, 1] != nil && self.host[/^\[(.*)\]$/, 1] !~
- Regexp.new("^[#{unreserved}#{sub_delims}:]*$")))
- raise InvalidURIError, "Invalid character in host: '#{self.host.to_s}'"
- end
- return nil
- end
-
- ##
- # Replaces the internal state of self with the specified URI's state.
- # Used in destructive operations to avoid massive code repetition.
- #
- # @param [Addressable::URI] uri The URI to replace self
with.
- #
- # @return [Addressable::URI] self
.
- def replace_self(uri)
- # Reset dependent values
- reset_ivs
-
- @scheme = uri.scheme
- @user = uri.user
- @password = uri.password
- @host = uri.host
- @port = uri.port
- @path = uri.path
- @query = uri.query
- @fragment = uri.fragment
- return self
- end
-
- ##
- # Splits path string with "/" (slash).
- # It is considered that there is empty string after last slash when
- # path ends with slash.
- #
- # @param [String] path The path to split.
- #
- # @return [Array
- # BinData::Struct.new(name: :my_struct, fields: ...)
- # array = BinData::Array.new(type: :my_struct)
- #
- module RegisterNamePlugin
-
- def self.included(base) #:nodoc:
- # The registered name may be provided explicitly.
- base.optional_parameter :name
- end
-
- def initialize_shared_instance
- if has_parameter?(:name)
- RegisteredClasses.register(get_parameter(:name), self)
- end
- super
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/offset.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/offset.rb
deleted file mode 100644
index 7b9a61e658c6e..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/offset.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-module BinData
- # WARNING: THIS IS UNSUPPORTED!!
- #
- # This was a (failed) experimental feature that allowed seeking within the
- # input stream. It remains here for backwards compatability for the few
- # people that used it.
- #
- # The official way to skip around the stream is to use BinData::Skip with
- # the `:to_abs_offset` parameter.
- #
- # == Parameters
- #
- # Parameters may be provided at initialisation to control the behaviour of
- # an object. These parameters are:
- #
- # [:check_offset] Raise an error if the current IO offset doesn't
- # meet this criteria. A boolean return indicates
- # success or failure. Any other return is compared
- # to the current offset. The variable +offset+
- # is made available to any lambda assigned to
- # this parameter. This parameter is only checked
- # before reading.
- # [:adjust_offset] Ensures that the current IO offset is at this
- # position before reading. This is like
- # :check_offset, except that it will
- # adjust the IO offset instead of raising an error.
- module CheckOrAdjustOffsetPlugin
-
- def self.included(base) #:nodoc:
- base.optional_parameters :check_offset, :adjust_offset
- base.mutually_exclusive_parameters :check_offset, :adjust_offset
- end
-
- def initialize_shared_instance
- extend CheckOffsetMixin if has_parameter?(:check_offset)
- extend AdjustOffsetMixin if has_parameter?(:adjust_offset)
- super
- end
-
- module CheckOffsetMixin
- def do_read(io) #:nodoc:
- check_offset(io)
- super(io)
- end
-
- #---------------
- private
-
- def check_offset(io)
- actual_offset = io.offset
- expected = eval_parameter(:check_offset, offset: actual_offset)
-
- if !expected
- raise ValidityError, "offset not as expected for #{debug_name}"
- elsif actual_offset != expected && expected != true
- raise ValidityError,
- "offset is '#{actual_offset}' but " +
- "expected '#{expected}' for #{debug_name}"
- end
- end
- end
-
- module AdjustOffsetMixin
- def do_read(io) #:nodoc:
- adjust_offset(io)
- super(io)
- end
-
- #---------------
- private
-
- def adjust_offset(io)
- actual_offset = io.offset
- expected = eval_parameter(:adjust_offset)
- if actual_offset != expected
- begin
- seek = expected - actual_offset
- io.seekbytes(seek)
- warn "adjusting stream position by #{seek} bytes" if $VERBOSE
- rescue
- raise ValidityError,
- "offset is '#{actual_offset}' but couldn't seek to " +
- "expected '#{expected}' for #{debug_name}"
- end
- end
- end
- end
- end
-
- # Add these offset options to Base
- class Base
- include CheckOrAdjustOffsetPlugin
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/params.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/params.rb
deleted file mode 100644
index cb34dff6820bc..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/params.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-require 'bindata/lazy'
-
-module BinData
- module AcceptedParametersPlugin
- # Mandatory parameters must be present when instantiating a data object.
- def mandatory_parameters(*args)
- accepted_parameters.mandatory(*args)
- end
-
- # Optional parameters may be present when instantiating a data object.
- def optional_parameters(*args)
- accepted_parameters.optional(*args)
- end
-
- # Default parameters can be overridden when instantiating a data object.
- def default_parameters(*args)
- accepted_parameters.default(*args)
- end
-
- # Mutually exclusive parameters may not all be present when
- # instantiating a data object.
- def mutually_exclusive_parameters(*args)
- accepted_parameters.mutually_exclusive(*args)
- end
-
- alias mandatory_parameter mandatory_parameters
- alias optional_parameter optional_parameters
- alias default_parameter default_parameters
-
- def accepted_parameters #:nodoc:
- @accepted_parameters ||= begin
- ancestor_params = superclass.respond_to?(:accepted_parameters) ?
- superclass.accepted_parameters : nil
- AcceptedParameters.new(ancestor_params)
- end
- end
-
- # BinData objects accept parameters when initializing. AcceptedParameters
- # allow a BinData class to declaratively identify accepted parameters as
- # mandatory, optional, default or mutually exclusive.
- class AcceptedParameters
- def initialize(ancestor_parameters = nil)
- if ancestor_parameters
- @mandatory = ancestor_parameters.mandatory.dup
- @optional = ancestor_parameters.optional.dup
- @default = ancestor_parameters.default.dup
- @mutually_exclusive = ancestor_parameters.mutually_exclusive.dup
- else
- @mandatory = []
- @optional = []
- @default = Hash.new
- @mutually_exclusive = []
- end
- end
-
- def mandatory(*args)
- unless args.empty?
- @mandatory.concat(to_syms(args))
- @mandatory.uniq!
- end
- @mandatory
- end
-
- def optional(*args)
- unless args.empty?
- @optional.concat(to_syms(args))
- @optional.uniq!
- end
- @optional
- end
-
- def default(args = nil)
- if args
- to_syms(args.keys) # call for side effect of validating names
- args.each_pair do |param, value|
- @default[param.to_sym] = value
- end
- end
- @default
- end
-
- def mutually_exclusive(*args)
- arg1 = args.shift
- until args.empty?
- args.each do |arg2|
- @mutually_exclusive.push([arg1.to_sym, arg2.to_sym])
- @mutually_exclusive.uniq!
- end
- arg1 = args.shift
- end
- @mutually_exclusive
- end
-
- def all
- (@mandatory + @optional + @default.keys).uniq
- end
-
- #---------------
- private
-
- def to_syms(args)
- syms = args.collect(&:to_sym)
- ensure_valid_names(syms)
- syms
- end
-
- def ensure_valid_names(names)
- invalid_names = self.class.invalid_parameter_names
- names.each do |name|
- if invalid_names.include?(name)
- raise NameError.new("Rename parameter '#{name}' " \
- "as it shadows an existing method.", name)
- end
- end
- end
-
- def self.invalid_parameter_names
- @invalid_names ||= begin
- all_names = LazyEvaluator.instance_methods(true)
- allowed_names = [:name, :type]
- invalid_names = (all_names - allowed_names).uniq
-
- Hash[*invalid_names.collect { |key| [key.to_sym, true] }.flatten]
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/primitive.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/primitive.rb
deleted file mode 100644
index 9b9bd8d41d5bd..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/primitive.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-require 'bindata/base_primitive'
-require 'bindata/dsl'
-require 'bindata/struct'
-
-module BinData
- # A Primitive is a declarative way to define a new BinData data type.
- # The data type must contain a primitive value only, i.e numbers or strings.
- # For new data types that contain multiple values see BinData::Record.
- #
- # To define a new data type, set fields as if for Record and add a
- # #get and #set method to extract / convert the data between the fields
- # and the #value of the object.
- #
- # require 'bindata'
- #
- # class PascalString < BinData::Primitive
- # uint8 :len, value: -> { data.length }
- # string :data, read_length: :len
- #
- # def get
- # self.data
- # end
- #
- # def set(v)
- # self.data = v
- # end
- # end
- #
- # ps = PascalString.new(initial_value: "hello")
- # ps.to_binary_s #=> "\005hello"
- # ps.read("\003abcde")
- # ps #=> "abc"
- #
- # # Unsigned 24 bit big endian integer
- # class Uint24be < BinData::Primitive
- # uint8 :byte1
- # uint8 :byte2
- # uint8 :byte3
- #
- # def get
- # (self.byte1 << 16) | (self.byte2 << 8) | self.byte3
- # end
- #
- # def set(v)
- # v = 0 if v < 0
- # v = 0xffffff if v > 0xffffff
- #
- # self.byte1 = (v >> 16) & 0xff
- # self.byte2 = (v >> 8) & 0xff
- # self.byte3 = v & 0xff
- # end
- # end
- #
- # u24 = Uint24be.new
- # u24.read("\x12\x34\x56")
- # "0x%x" % u24 #=> 0x123456
- #
- # == Parameters
- #
- # Primitive objects accept all the parameters that BinData::BasePrimitive do.
- #
- class Primitive < BasePrimitive
- extend DSLMixin
-
- unregister_self
- dsl_parser :primitive
- arg_processor :primitive
-
- mandatory_parameter :struct_params
-
- def initialize_instance
- super
- @struct = BinData::Struct.new(get_parameter(:struct_params), self)
- end
-
- def respond_to?(symbol, include_private = false) #:nodoc:
- @struct.respond_to?(symbol, include_private) || super
- end
-
- def method_missing(symbol, *args, &block) #:nodoc:
- if @struct.respond_to?(symbol)
- @struct.__send__(symbol, *args, &block)
- else
- super
- end
- end
-
- def assign(val)
- super(val)
- set(_value)
- @value = get
- end
-
- def debug_name_of(child) #:nodoc:
- debug_name + "-internal-"
- end
-
- def do_write(io)
- set(_value)
- @struct.do_write(io)
- end
-
- def do_num_bytes
- set(_value)
- @struct.do_num_bytes
- end
-
- #---------------
- private
-
- def sensible_default
- get
- end
-
- def read_and_return_value(io)
- @struct.do_read(io)
- get
- end
-
- ###########################################################################
- # To be implemented by subclasses
-
- # Extracts the value for this data object from the fields of the
- # internal struct.
- def get
- raise NotImplementedError
- end
-
- # Sets the fields of the internal struct to represent +v+.
- def set(v)
- raise NotImplementedError
- end
-
- # To be implemented by subclasses
- ###########################################################################
- end
-
- class PrimitiveArgProcessor < BaseArgProcessor
- def sanitize_parameters!(obj_class, params)
- params[:struct_params] = params.create_sanitized_params(obj_class.dsl_params, BinData::Struct)
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/record.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/record.rb
deleted file mode 100644
index b011cf5e1c8dd..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/record.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require 'bindata/dsl'
-require 'bindata/struct'
-
-module BinData
- # A Record is a declarative wrapper around Struct.
- #
- # See +Struct+ for more info.
- class Record < BinData::Struct
- extend DSLMixin
-
- unregister_self
- dsl_parser :struct
- arg_processor :record
- end
-
- class RecordArgProcessor < StructArgProcessor
- include MultiFieldArgSeparator
-
- def sanitize_parameters!(obj_class, params)
- super(obj_class, params.merge!(obj_class.dsl_params))
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/registry.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/registry.rb
deleted file mode 100644
index fc47740bd5594..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/registry.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-module BinData
-
- class UnRegisteredTypeError < StandardError ; end
-
- # This registry contains a register of name -> class mappings.
- #
- # Numerics (integers and floating point numbers) have an endian property as
- # part of their name (e.g. int32be, float_le).
- #
- # Classes can be looked up based on their full name or an abbreviated +name+
- # with +hints+.
- #
- # There are two hints supported, :endian and :search_prefix.
- #
- # #lookup("int32", { endian: :big }) will return Int32Be.
- #
- # #lookup("my_type", { search_prefix: :ns }) will return NsMyType.
- #
- # Names are stored in under_score_style, not camelCase.
- class Registry
-
- def initialize
- @registry = {}
- end
-
- def register(name, class_to_register)
- return if name.nil? || class_to_register.nil?
-
- formatted_name = underscore_name(name)
- warn_if_name_is_already_registered(formatted_name, class_to_register)
-
- @registry[formatted_name] = class_to_register
- end
-
- def unregister(name)
- @registry.delete(underscore_name(name))
- end
-
- def lookup(name, hints = {})
- the_class = @registry[normalize_name(name, hints)]
- if the_class
- the_class
- elsif @registry[normalize_name(name, hints.merge(endian: :big))]
- raise(UnRegisteredTypeError, "#{name}, do you need to specify endian?")
- else
- raise(UnRegisteredTypeError, name)
- end
- end
-
- # Convert CamelCase +name+ to underscore style.
- def underscore_name(name)
- name.
- to_s.
- sub(/.*::/, "").
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
- tr("-", "_").
- downcase
- end
-
- #---------------
- private
-
- def normalize_name(name, hints)
- name = underscore_name(name)
-
- if !registered?(name)
- search_prefix = [""].concat(Array(hints[:search_prefix]))
- search_prefix.each do |prefix|
- nwp = name_with_prefix(name, prefix)
- if registered?(nwp)
- name = nwp
- break
- end
-
- nwe = name_with_endian(nwp, hints[:endian])
- if registered?(nwe)
- name = nwe
- break
- end
- end
- end
-
- name
- end
-
- def name_with_prefix(name, prefix)
- prefix = prefix.to_s.chomp("_")
- if prefix == ""
- name
- else
- "#{prefix}_#{name}"
- end
- end
-
- def name_with_endian(name, endian)
- return name if endian.nil?
-
- suffix = (endian == :little) ? "le" : "be"
- if /^u?int\d+$/ =~ name
- name + suffix
- else
- name + "_" + suffix
- end
- end
-
- def registered?(name)
- register_dynamic_class(name) unless @registry.key?(name)
-
- @registry.key?(name)
- end
-
- def register_dynamic_class(name)
- if /^u?int\d+(le|be)$/ =~ name || /^s?bit\d+(le)?$/ =~ name
- class_name = name.gsub(/(?:^|_)(.)/) { $1.upcase }
- begin
- BinData.const_get(class_name)
- rescue NameError
- end
- end
- end
-
- def warn_if_name_is_already_registered(name, class_to_register)
- prev_class = @registry[name]
- if $VERBOSE && prev_class && prev_class != class_to_register
- warn "warning: replacing registered class #{prev_class} " \
- "with #{class_to_register}"
- end
- end
- end
-
- # A singleton registry of all registered classes.
- RegisteredClasses = Registry.new
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/rest.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/rest.rb
deleted file mode 100644
index cdc104459c568..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/rest.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require "bindata/base_primitive"
-
-module BinData
- # Rest will consume the input stream from the current position to the end of
- # the stream. This will mainly be useful for debugging and developing.
- #
- # require 'bindata'
- #
- # class A < BinData::Record
- # string :a, read_length: 5
- # rest :rest
- # end
- #
- # obj = A.read("abcdefghij")
- # obj.a #=> "abcde"
- # obj.rest #=" "fghij"
- #
- class Rest < BinData::BasePrimitive
- #---------------
- private
-
- def value_to_binary_string(val)
- val
- end
-
- def read_and_return_value(io)
- io.read_all_bytes
- end
-
- def sensible_default
- ""
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/sanitize.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/sanitize.rb
deleted file mode 100644
index 7325b206b0c47..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/sanitize.rb
+++ /dev/null
@@ -1,372 +0,0 @@
-require 'bindata/registry'
-
-module BinData
-
- # Subclasses of this are sanitized
- class SanitizedParameter; end
-
- class SanitizedPrototype < SanitizedParameter
- def initialize(obj_type, obj_params, hints)
- raw_hints = hints.dup
- if raw_hints[:endian].respond_to?(:endian)
- raw_hints[:endian] = raw_hints[:endian].endian
- end
- obj_params ||= {}
-
- if BinData::Base === obj_type
- obj_class = obj_type
- else
- obj_class = RegisteredClasses.lookup(obj_type, raw_hints)
- end
-
- if BinData::Base === obj_class
- @factory = obj_class
- else
- @obj_class = obj_class
- @obj_params = SanitizedParameters.new(obj_params, @obj_class, hints)
- end
- end
-
- def has_parameter?(param)
- if defined? @factory
- @factory.has_parameter?(param)
- else
- @obj_params.has_parameter?(param)
- end
- end
-
- def instantiate(value = nil, parent = nil)
- @factory ||= @obj_class.new(@obj_params)
-
- @factory.new(value, parent)
- end
- end
- #----------------------------------------------------------------------------
-
- class SanitizedField < SanitizedParameter
- def initialize(name, field_type, field_params, hints)
- @name = name
- @prototype = SanitizedPrototype.new(field_type, field_params, hints)
- end
-
- attr_reader :prototype
-
- def name_as_sym
- @name.nil? ? nil : @name.to_sym
- end
-
- def name
- @name
- end
-
- def has_parameter?(param)
- @prototype.has_parameter?(param)
- end
-
- def instantiate(value = nil, parent = nil)
- @prototype.instantiate(value, parent)
- end
- end
- #----------------------------------------------------------------------------
-
- class SanitizedFields < SanitizedParameter
- include Enumerable
-
- def initialize(hints, base_fields = nil)
- @hints = hints
- if base_fields
- @fields = base_fields.raw_fields
- else
- @fields = []
- end
- end
-
- def add_field(type, name, params)
- name = nil if name == ""
-
- @fields << SanitizedField.new(name, type, params, @hints)
- end
-
- def raw_fields
- @fields.dup
- end
-
- def [](idx)
- @fields[idx]
- end
-
- def empty?
- @fields.empty?
- end
-
- def length
- @fields.length
- end
-
- def each(&block)
- @fields.each(&block)
- end
-
- def field_names
- @fields.collect(&:name_as_sym)
- end
-
- def field_name?(name)
- @fields.detect { |f| f.name_as_sym == name.to_sym }
- end
-
- def all_field_names_blank?
- @fields.all? { |f| f.name.nil? }
- end
-
- def no_field_names_blank?
- @fields.all? { |f| f.name != nil }
- end
-
- def any_field_has_parameter?(parameter)
- @fields.any? { |f| f.has_parameter?(parameter) }
- end
- end
- #----------------------------------------------------------------------------
-
- class SanitizedChoices < SanitizedParameter
- def initialize(choices, hints)
- @choices = {}
- choices.each_pair do |key, val|
- if SanitizedParameter === val
- prototype = val
- else
- type, param = val
- prototype = SanitizedPrototype.new(type, param, hints)
- end
-
- if key == :default
- @choices.default = prototype
- else
- @choices[key] = prototype
- end
- end
- end
-
- def [](key)
- @choices[key]
- end
- end
- #----------------------------------------------------------------------------
-
- class SanitizedBigEndian < SanitizedParameter
- def endian
- :big
- end
- end
-
- class SanitizedLittleEndian < SanitizedParameter
- def endian
- :little
- end
- end
- #----------------------------------------------------------------------------
-
- # BinData objects are instantiated with parameters to determine their
- # behaviour. These parameters must be sanitized to ensure their values
- # are valid. When instantiating many objects with identical parameters,
- # such as an array of records, there is much duplicated sanitizing.
- #
- # The purpose of the sanitizing code is to eliminate the duplicated
- # validation.
- #
- # SanitizedParameters is a hash-like collection of parameters. Its purpose
- # is to recursively sanitize the parameters of an entire BinData object chain
- # at a single time.
- class SanitizedParameters < Hash
-
- # Memoized constants
- BIG_ENDIAN = SanitizedBigEndian.new
- LITTLE_ENDIAN = SanitizedLittleEndian.new
-
- class << self
- def sanitize(parameters, the_class)
- if SanitizedParameters === parameters
- parameters
- else
- SanitizedParameters.new(parameters, the_class, {})
- end
- end
- end
-
- def initialize(parameters, the_class, hints)
- parameters.each_pair { |key, value| self[key.to_sym] = value }
-
- @the_class = the_class
-
- if hints[:endian]
- self[:endian] ||= hints[:endian]
- end
-
- if hints[:search_prefix] && !hints[:search_prefix].empty?
- self[:search_prefix] = Array(self[:search_prefix]).concat(Array(hints[:search_prefix]))
- end
-
- sanitize!
- end
-
- alias_method :has_parameter?, :key?
-
- def has_at_least_one_of?(*keys)
- keys.each do |key|
- return true if has_parameter?(key)
- end
-
- false
- end
-
- def warn_replacement_parameter(bad_key, suggested_key)
- if has_parameter?(bad_key)
- Kernel.warn ":#{bad_key} is not used with #{@the_class}. " \
- "You probably want to change this to :#{suggested_key}"
- end
- end
-
-# def warn_renamed_parameter(old_key, new_key)
-# val = delete(old_key)
-# if val
-# self[new_key] = val
-# Kernel.warn ":#{old_key} has been renamed to :#{new_key} in #{@the_class}. " \
-# "Using :#{old_key} is now deprecated and will be removed in the future"
-# end
-# end
-
- def must_be_integer(*keys)
- keys.each do |key|
- if has_parameter?(key)
- parameter = self[key]
- unless Symbol === parameter ||
- parameter.respond_to?(:arity) ||
- parameter.respond_to?(:to_int)
- raise ArgumentError, "parameter '#{key}' in #{@the_class} must " \
- "evaluate to an integer, got #{parameter.class}"
- end
- end
- end
- end
-
- def rename_parameter(old_key, new_key)
- if has_parameter?(old_key)
- self[new_key] = delete(old_key)
- end
- end
-
- def sanitize_object_prototype(key)
- sanitize(key) { |obj_type, obj_params| create_sanitized_object_prototype(obj_type, obj_params) }
- end
-
- def sanitize_fields(key, &block)
- sanitize(key) do |fields|
- sanitized_fields = create_sanitized_fields
- yield(fields, sanitized_fields)
- sanitized_fields
- end
- end
-
- def sanitize_choices(key, &block)
- sanitize(key) do |obj|
- create_sanitized_choices(yield(obj))
- end
- end
-
- def sanitize_endian(key)
- sanitize(key) { |endian| create_sanitized_endian(endian) }
- end
-
- def sanitize(key, &block)
- if needs_sanitizing?(key)
- self[key] = yield(self[key])
- end
- end
-
- def create_sanitized_params(params, the_class)
- SanitizedParameters.new(params, the_class, hints)
- end
-
- def hints
- { endian: self[:endian], search_prefix: self[:search_prefix] }
- end
-
- #---------------
- private
-
- def sanitize!
- ensure_no_nil_values
- merge_default_parameters!
-
- @the_class.arg_processor.sanitize_parameters!(@the_class, self)
-
- ensure_mandatory_parameters_exist
- ensure_mutual_exclusion_of_parameters
- end
-
- def needs_sanitizing?(key)
- has_key?(key) && ! self[key].is_a?(SanitizedParameter)
- end
-
- def ensure_no_nil_values
- each do |key, value|
- if value.nil?
- raise ArgumentError,
- "parameter '#{key}' has nil value in #{@the_class}"
- end
- end
- end
-
- def merge_default_parameters!
- @the_class.default_parameters.each do |key, value|
- self[key] = value unless has_key?(key)
- end
- end
-
- def ensure_mandatory_parameters_exist
- @the_class.mandatory_parameters.each do |key|
- unless has_parameter?(key)
- raise ArgumentError,
- "parameter '#{key}' must be specified in #{@the_class}"
- end
- end
- end
-
- def ensure_mutual_exclusion_of_parameters
- return if length < 2
-
- @the_class.mutually_exclusive_parameters.each do |key1, key2|
- if has_parameter?(key1) && has_parameter?(key2)
- raise ArgumentError, "params '#{key1}' and '#{key2}' " \
- "are mutually exclusive in #{@the_class}"
- end
- end
- end
-
- def create_sanitized_endian(endian)
- if endian == :big
- BIG_ENDIAN
- elsif endian == :little
- LITTLE_ENDIAN
- elsif endian == :big_and_little
- raise ArgumentError, "endian: :big or endian: :little is required"
- else
- raise ArgumentError, "unknown value for endian '#{endian}'"
- end
- end
-
- def create_sanitized_choices(choices)
- SanitizedChoices.new(choices, hints)
- end
-
- def create_sanitized_fields
- SanitizedFields.new(hints)
- end
-
- def create_sanitized_object_prototype(obj_type, obj_params)
- SanitizedPrototype.new(obj_type, obj_params, hints)
- end
- end
- #----------------------------------------------------------------------------
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/skip.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/skip.rb
deleted file mode 100644
index 40d4fe940af67..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/skip.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-require "bindata/base_primitive"
-
-module BinData
- # Skip will skip over bytes from the input stream. If the stream is not
- # seekable, then the bytes are consumed and discarded.
- #
- # When writing, skip will write the appropriate number of zero bytes.
- #
- # require 'bindata'
- #
- # class A < BinData::Record
- # skip length: 5
- # string :a, read_length: 5
- # end
- #
- # obj = A.read("abcdefghij")
- # obj.a #=> "fghij"
- #
- #
- # class B < BinData::Record
- # skip until_valid: [:string, {read_length: 2, assert: "ef"} ]
- # string :b, read_length: 5
- # end
- #
- # obj = B.read("abcdefghij")
- # obj.b #=> "efghi"
- #
- #
- # == Parameters
- #
- # Skip objects accept all the params that BinData::BasePrimitive
- # does, as well as the following:
- #
- # :length:: The number of bytes to skip.
- # :to_abs_offset:: Skips to the given absolute offset.
- # :until_valid:: Skips untils a given byte pattern is matched.
- # This parameter contains a type that will raise
- # a BinData::ValidityError unless an acceptable byte
- # sequence is found. The type is represented by a
- # Symbol, or if the type is to have params #
- # passed to it, then it should be provided as #
- # [type_symbol, hash_params].
- #
- class Skip < BinData::BasePrimitive
- arg_processor :skip
-
- optional_parameters :length, :to_abs_offset, :until_valid
- mutually_exclusive_parameters :length, :to_abs_offset, :until_valid
-
- def initialize_shared_instance
- extend SkipLengthPlugin if has_parameter?(:length)
- extend SkipToAbsOffsetPlugin if has_parameter?(:to_abs_offset)
- extend SkipUntilValidPlugin if has_parameter?(:until_valid)
- super
- end
-
- #---------------
- private
-
- def value_to_binary_string(val)
- len = skip_length
- if len < 0
- raise ValidityError, "#{debug_name} attempted to seek backwards by #{len.abs} bytes"
- end
-
- "\000" * skip_length
- end
-
- def read_and_return_value(io)
- len = skip_length
- if len < 0
- raise ValidityError, "#{debug_name} attempted to seek backwards by #{len.abs} bytes"
- end
-
- io.seekbytes(len)
- ""
- end
-
- def sensible_default
- ""
- end
- end
-
- class SkipArgProcessor < BaseArgProcessor
- def sanitize_parameters!(obj_class, params)
- unless params.has_at_least_one_of?(:length, :to_abs_offset, :until_valid)
- raise ArgumentError,
- "#{obj_class} requires either :length, :to_abs_offset or :until_valid"
- end
- params.must_be_integer(:to_abs_offset, :length)
- params.sanitize_object_prototype(:until_valid)
- end
- end
-
- # Logic for the :length parameter
- module SkipLengthPlugin
- def skip_length
- eval_parameter(:length)
- end
- end
-
- # Logic for the :to_abs_offset parameter
- module SkipToAbsOffsetPlugin
- def skip_length
- eval_parameter(:to_abs_offset) - abs_offset
- end
- end
-
- # Logic for the :until_valid parameter
- module SkipUntilValidPlugin
- def skip_length
- # no skipping when writing
- 0
- end
-
- def read_and_return_value(io)
- prototype = get_parameter(:until_valid)
- validator = prototype.instantiate(nil, self)
-
- valid = false
- until valid
- begin
- io.with_readahead do
- validator.read(io)
- valid = true
- end
- rescue ValidityError
- io.readbytes(1)
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/string.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/string.rb
deleted file mode 100644
index cf744ae2dfad3..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/string.rb
+++ /dev/null
@@ -1,153 +0,0 @@
-require "bindata/base_primitive"
-
-module BinData
- # A String is a sequence of bytes. This is the same as strings in Ruby 1.8.
- # The issue of character encoding is ignored by this class.
- #
- # require 'bindata'
- #
- # data = "abcdefghij"
- #
- # obj = BinData::String.new(read_length: 5)
- # obj.read(data)
- # obj #=> "abcde"
- #
- # obj = BinData::String.new(length: 6)
- # obj.read(data)
- # obj #=> "abcdef"
- # obj.assign("abcdefghij")
- # obj #=> "abcdef"
- # obj.assign("abcd")
- # obj #=> "abcd\000\000"
- #
- # obj = BinData::String.new(length: 6, trim_padding: true)
- # obj.assign("abcd")
- # obj #=> "abcd"
- # obj.to_binary_s #=> "abcd\000\000"
- #
- # obj = BinData::String.new(length: 6, pad_byte: 'A')
- # obj.assign("abcd")
- # obj #=> "abcdAA"
- # obj.to_binary_s #=> "abcdAA"
- #
- # == Parameters
- #
- # String objects accept all the params that BinData::BasePrimitive
- # does, as well as the following:
- #
- # :read_length:: The length in bytes to use when reading a value.
- # :length:: The fixed length of the string. If a shorter
- # string is set, it will be padded to this length.
- # :pad_byte:: The byte to use when padding a string to a
- # set length. Valid values are Integers and
- # Strings of length 1. "\0" is the default.
- # :pad_front:: Signifies that the padding occurs at the front
- # of the string rather than the end. Default
- # is false.
- # :trim_padding:: Boolean, default false. If set, #value will
- # return the value with all pad_bytes trimmed
- # from the end of the string. The value will
- # not be trimmed when writing.
- class String < BinData::BasePrimitive
- arg_processor :string
-
- optional_parameters :read_length, :length, :trim_padding, :pad_front, :pad_left
- default_parameters pad_byte: "\0"
- mutually_exclusive_parameters :read_length, :length
- mutually_exclusive_parameters :length, :value
-
- def initialize_shared_instance
- if (has_parameter?(:value) || has_parameter?(:asserted_value)) &&
- !has_parameter?(:read_length)
- extend WarnNoReadLengthPlugin
- end
- super
- end
-
- def assign(val)
- super(binary_string(val))
- end
-
- def snapshot
- # override to trim padding
- snap = super
- snap = clamp_to_length(snap)
-
- if get_parameter(:trim_padding)
- trim_padding(snap)
- else
- snap
- end
- end
-
- #---------------
- private
-
- def clamp_to_length(str)
- str = binary_string(str)
-
- len = eval_parameter(:length) || str.length
- if str.length == len
- str
- elsif str.length > len
- str.slice(0, len)
- else
- padding = (eval_parameter(:pad_byte) * (len - str.length))
- if get_parameter(:pad_front)
- padding + str
- else
- str + padding
- end
- end
- end
-
- def trim_padding(str)
- if get_parameter(:pad_front)
- str.sub(/\A#{eval_parameter(:pad_byte)}*/, "")
- else
- str.sub(/#{eval_parameter(:pad_byte)}*\z/, "")
- end
- end
-
- def value_to_binary_string(val)
- clamp_to_length(val)
- end
-
- def read_and_return_value(io)
- len = eval_parameter(:read_length) || eval_parameter(:length) || 0
- io.readbytes(len)
- end
-
- def sensible_default
- ""
- end
- end
-
- class StringArgProcessor < BaseArgProcessor
- def sanitize_parameters!(obj_class, params)
- params.warn_replacement_parameter(:initial_length, :read_length)
- params.must_be_integer(:read_length, :length)
- params.rename_parameter(:pad_left, :pad_front)
- params.sanitize(:pad_byte) { |byte| sanitized_pad_byte(byte) }
- end
-
- #-------------
- private
-
- def sanitized_pad_byte(byte)
- pad_byte = byte.is_a?(Integer) ? byte.chr : byte.to_s
- if pad_byte.bytesize > 1
- raise ArgumentError, ":pad_byte must not contain more than 1 byte"
- end
- pad_byte
- end
- end
-
- # Warns when reading if :value && no :read_length
- module WarnNoReadLengthPlugin
- def read_and_return_value(io)
- warn "#{debug_name} does not have a :read_length parameter - returning empty string"
- ""
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/stringz.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/stringz.rb
deleted file mode 100644
index ff047fca85567..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/stringz.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-require "bindata/base_primitive"
-
-module BinData
- # A BinData::Stringz object is a container for a zero ("\0") terminated
- # string.
- #
- # For convenience, the zero terminator is not necessary when setting the
- # value. Likewise, the returned value will not be zero terminated.
- #
- # require 'bindata'
- #
- # data = "abcd\x00efgh"
- #
- # obj = BinData::Stringz.new
- # obj.read(data)
- # obj.snapshot #=> "abcd"
- # obj.num_bytes #=> 5
- # obj.to_binary_s #=> "abcd\000"
- #
- # == Parameters
- #
- # Stringz objects accept all the params that BinData::BasePrimitive
- # does, as well as the following:
- #
- # :max_length:: The maximum length of the string including the zero
- # byte.
- class Stringz < BinData::BasePrimitive
-
- optional_parameters :max_length
-
- def assign(val)
- super(binary_string(val))
- end
-
- def snapshot
- # override to always remove trailing zero bytes
- result = super
- trim_and_zero_terminate(result).chomp("\0")
- end
-
- #---------------
- private
-
- def value_to_binary_string(val)
- trim_and_zero_terminate(val)
- end
-
- def read_and_return_value(io)
- max_length = eval_parameter(:max_length)
- str = ""
- i = 0
- ch = nil
-
- # read until zero byte or we have read in the max number of bytes
- while ch != "\0" && i != max_length
- ch = io.readbytes(1)
- str += ch
- i += 1
- end
-
- trim_and_zero_terminate(str)
- end
-
- def sensible_default
- ""
- end
-
- def trim_and_zero_terminate(str)
- result = binary_string(str)
- truncate_after_first_zero_byte!(result)
- trim_to!(result, eval_parameter(:max_length))
- append_zero_byte_if_needed!(result)
- result
- end
-
- def truncate_after_first_zero_byte!(str)
- str.sub!(/([^\0]*\0).*/, '\1')
- end
-
- def trim_to!(str, max_length = nil)
- if max_length
- max_length = 1 if max_length < 1
- str.slice!(max_length..-1)
- if str.length == max_length && str[-1, 1] != "\0"
- str[-1, 1] = "\0"
- end
- end
- end
-
- def append_zero_byte_if_needed!(str)
- if str.length == 0 || str[-1, 1] != "\0"
- str << "\0"
- end
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/struct.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/struct.rb
deleted file mode 100644
index f990036e1b74a..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/struct.rb
+++ /dev/null
@@ -1,422 +0,0 @@
-require 'bindata/base'
-require 'bindata/delayed_io'
-
-module BinData
-
- class Base
- optional_parameter :onlyif, :byte_align # Used by Struct
- end
-
- # A Struct is an ordered collection of named data objects.
- #
- # require 'bindata'
- #
- # class Tuple < BinData::Record
- # int8 :x
- # int8 :y
- # int8 :z
- # end
- #
- # obj = BinData::Struct.new(hide: :a,
- # fields: [ [:int32le, :a],
- # [:int16le, :b],
- # [:tuple, :s] ])
- # obj.field_names =># [:b, :s]
- #
- #
- # == Parameters
- #
- # Parameters may be provided at initialisation to control the behaviour of
- # an object. These params are:
- #
- # :fields:: An array specifying the fields for this struct.
- # Each element of the array is of the form [type, name,
- # params]. Type is a symbol representing a registered
- # type. Name is the name of this field. Params is an
- # optional hash of parameters to pass to this field
- # when instantiating it. If name is "" or nil, then
- # that field is anonymous and behaves as a hidden field.
- # :hide:: A list of the names of fields that are to be hidden
- # from the outside world. Hidden fields don't appear
- # in #snapshot or #field_names but are still accessible
- # by name.
- # :endian:: Either :little or :big. This specifies the default
- # endian of any numerics in this struct, or in any
- # nested data objects.
- # :search_prefix:: Allows abbreviated type names. If a type is
- # unrecognised, then each prefix is applied until
- # a match is found.
- #
- # == Field Parameters
- #
- # Fields may have have extra parameters as listed below:
- #
- # [:onlyif] Used to indicate a data object is optional.
- # if +false+, this object will not be included in any
- # calls to #read, #write, #num_bytes or #snapshot.
- # [:byte_align] This field's rel_offset must be a multiple of
- # :byte_align.
- class Struct < BinData::Base
- arg_processor :struct
-
- mandatory_parameter :fields
- optional_parameters :endian, :search_prefix, :hide
-
- # These reserved words may not be used as field names
- RESERVED =
- Hash[*
- (Hash.instance_methods +
- %w{alias and begin break case class def defined do else elsif
- end ensure false for if in module next nil not or redo
- rescue retry return self super then true undef unless until
- when while yield} +
- %w{array element index value} +
- %w{type initial_length read_until} +
- %w{fields endian search_prefix hide only_if byte_align} +
- %w{choices selection copy_on_change} +
- %w{read_abs_offset struct_params}).collect(&:to_sym).
- uniq.collect { |key| [key, true] }.flatten
- ]
-
- def initialize_shared_instance
- fields = get_parameter(:fields)
- @field_names = fields.field_names.freeze
- extend ByteAlignPlugin if fields.any_field_has_parameter?(:byte_align)
- define_field_accessors
- super
- end
-
- def initialize_instance
- @field_objs = []
- end
-
- def clear #:nodoc:
- @field_objs.each { |f| f.clear unless f.nil? }
- end
-
- def clear? #:nodoc:
- @field_objs.all? { |f| f.nil? || f.clear? }
- end
-
- def assign(val)
- clear
- assign_fields(val)
- end
-
- def snapshot
- snapshot = Snapshot.new
- field_names.each do |name|
- obj = find_obj_for_name(name)
- snapshot[name] = obj.snapshot if include_obj?(obj)
- end
- snapshot
- end
-
- # Returns a list of the names of all fields accessible through this
- # object. +include_hidden+ specifies whether to include hidden names
- # in the listing.
- def field_names(include_hidden = false)
- if include_hidden
- @field_names.compact
- else
- hidden = get_parameter(:hide) || []
- @field_names.compact - hidden
- end
- end
-
- def debug_name_of(child) #:nodoc:
- field_name = @field_names[find_index_of(child)]
- "#{debug_name}.#{field_name}"
- end
-
- def offset_of(child) #:nodoc:
- instantiate_all_objs
- sum = sum_num_bytes_below_index(find_index_of(child))
- child.bit_aligned? ? sum.floor : sum.ceil
- end
-
- def do_read(io) #:nodoc:
- instantiate_all_objs
- @field_objs.each { |f| f.do_read(io) if include_obj_for_io?(f) }
- end
-
- def do_write(io) #:nodoc
- instantiate_all_objs
- @field_objs.each { |f| f.do_write(io) if include_obj_for_io?(f) }
- end
-
- def do_num_bytes #:nodoc:
- instantiate_all_objs
- sum_num_bytes_for_all_fields
- end
-
- def [](key)
- find_obj_for_name(key)
- end
-
- def []=(key, value)
- obj = find_obj_for_name(key)
- if obj
- obj.assign(value)
- end
- end
-
- def key?(key)
- @field_names.index(base_field_name(key))
- end
-
- def each_pair
- @field_names.compact.each do |name|
- yield [name, find_obj_for_name(name)]
- end
- end
-
- #---------------
- private
-
- def define_field_accessors
- get_parameter(:fields).each_with_index do |field, i|
- name = field.name_as_sym
- define_field_accessors_for(name, i) if name
- end
- end
-
- def define_field_accessors_for(name, index)
- define_singleton_method(name) do
- instantiate_obj_at(index) if @field_objs[index].nil?
- @field_objs[index]
- end
- define_singleton_method("#{name}=") do |*vals|
- instantiate_obj_at(index) if @field_objs[index].nil?
- @field_objs[index].assign(*vals)
- end
- define_singleton_method("#{name}?") do
- instantiate_obj_at(index) if @field_objs[index].nil?
- include_obj?(@field_objs[index])
- end
- end
-
- def find_index_of(obj)
- @field_objs.index { |el| el.equal?(obj) }
- end
-
- def find_obj_for_name(name)
- index = @field_names.index(base_field_name(name))
- if index
- instantiate_obj_at(index)
- @field_objs[index]
- else
- nil
- end
- end
-
- def base_field_name(name)
- name.to_s.sub(/(=|\?)\z/, "").to_sym
- end
-
- def instantiate_all_objs
- @field_names.each_index { |i| instantiate_obj_at(i) }
- end
-
- def instantiate_obj_at(index)
- if @field_objs[index].nil?
- field = get_parameter(:fields)[index]
- @field_objs[index] = field.instantiate(nil, self)
- end
- end
-
- def assign_fields(val)
- src = as_stringified_hash(val)
-
- @field_names.compact.each do |name|
- obj = find_obj_for_name(name)
- if obj && src.key?(name)
- obj.assign(src[name])
- end
- end
- end
-
- def as_stringified_hash(val)
- if BinData::Struct === val
- val
- elsif val.nil?
- {}
- else
- hash = Snapshot.new
- val.each_pair { |k,v| hash[k] = v }
- hash
- end
- end
-
- def sum_num_bytes_for_all_fields
- sum_num_bytes_below_index(@field_objs.length)
- end
-
- def sum_num_bytes_below_index(index)
- (0...index).inject(0) do |sum, i|
- obj = @field_objs[i]
- if include_obj?(obj)
- nbytes = obj.do_num_bytes
- (nbytes.is_a?(Integer) ? sum.ceil : sum) + nbytes
- else
- sum
- end
- end
- end
-
- def include_obj_for_io?(obj)
- # Used by #do_read and #do_write, to ensure the stream is passed to
- # DelayedIO objects for delayed processing.
- include_obj?(obj) || DelayedIO === obj
- end
-
- def include_obj?(obj)
- !obj.has_parameter?(:onlyif) || obj.eval_parameter(:onlyif)
- end
-
- # A hash that can be accessed via attributes.
- class Snapshot < ::Hash #:nodoc:
- def []=(key, value)
- super unless value.nil?
- end
-
- def respond_to?(symbol, include_private = false)
- key?(symbol) || super
- end
-
- def method_missing(symbol, *args)
- key?(symbol) ? self[symbol] : super
- end
- end
- end
-
- # Align fields to a multiple of :byte_align
- module ByteAlignPlugin
- def do_read(io)
- initial_offset = io.offset
- instantiate_all_objs
- @field_objs.each do |f|
- if include_obj?(f)
- if align_obj?(f)
- io.seekbytes(bytes_to_align(f, io.offset - initial_offset))
- end
- f.do_read(io)
- end
- end
- end
-
- def do_write(io)
- initial_offset = io.offset
- instantiate_all_objs
- @field_objs.each do |f|
- if include_obj?(f)
- if align_obj?(f)
- io.writebytes("\x00" * bytes_to_align(f, io.offset - initial_offset))
- end
- f.do_write(io)
- end
- end
- end
-
- def sum_num_bytes_below_index(index)
- sum = 0
- (0...@field_objs.length).each do |i|
- obj = @field_objs[i]
- if include_obj?(obj)
- sum = sum.ceil + bytes_to_align(obj, sum.ceil) if align_obj?(obj)
-
- break if i >= index
-
- nbytes = obj.do_num_bytes
- sum = (nbytes.is_a?(Integer) ? sum.ceil : sum) + nbytes
- end
- end
-
- sum
- end
-
- def bytes_to_align(obj, rel_offset)
- align = obj.eval_parameter(:byte_align)
- (align - (rel_offset % align)) % align
- end
-
- def align_obj?(obj)
- obj.has_parameter?(:byte_align)
- end
- end
-
- class StructArgProcessor < BaseArgProcessor
- def sanitize_parameters!(obj_class, params)
- sanitize_endian(params)
- sanitize_search_prefix(params)
- sanitize_fields(obj_class, params)
- sanitize_hide(params)
- end
-
- #-------------
- private
-
- def sanitize_endian(params)
- params.sanitize_endian(:endian)
- end
-
- def sanitize_search_prefix(params)
- params.sanitize(:search_prefix) do |sprefix|
- search_prefix = []
- Array(sprefix).each do |prefix|
- prefix = prefix.to_s.chomp("_")
- search_prefix << prefix if prefix != ""
- end
-
- search_prefix
- end
- end
-
- def sanitize_fields(obj_class, params)
- params.sanitize_fields(:fields) do |fields, sanitized_fields|
- fields.each do |ftype, fname, fparams|
- sanitized_fields.add_field(ftype, fname, fparams)
- end
-
- field_names = sanitized_field_names(sanitized_fields)
- ensure_field_names_are_valid(obj_class, field_names)
- end
- end
-
- def sanitize_hide(params)
- params.sanitize(:hide) do |hidden|
- field_names = sanitized_field_names(params[:fields])
- hfield_names = hidden_field_names(hidden)
-
- hfield_names & field_names
- end
- end
-
- def sanitized_field_names(sanitized_fields)
- sanitized_fields.field_names.compact
- end
-
- def hidden_field_names(hidden)
- (hidden || []).collect(&:to_sym)
- end
-
- def ensure_field_names_are_valid(obj_class, field_names)
- reserved_names = BinData::Struct::RESERVED
-
- field_names.each do |name|
- if obj_class.method_defined?(name)
- raise NameError.new("Rename field '#{name}' in #{obj_class}, " \
- "as it shadows an existing method.", name)
- end
- if reserved_names.include?(name)
- raise NameError.new("Rename field '#{name}' in #{obj_class}, " \
- "as it is a reserved name.", name)
- end
- if field_names.count(name) != 1
- raise NameError.new("field '#{name}' in #{obj_class}, " \
- "is defined multiple times.", name)
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/trace.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/trace.rb
deleted file mode 100644
index 4e4f9ba59c477..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/trace.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-module BinData
- # reference to the current tracer
- @tracer ||= nil
-
- class Tracer #:nodoc:
- def initialize(io)
- @trace_io = io
- end
-
- def trace(msg)
- @trace_io.puts(msg)
- end
-
- def trace_obj(obj_name, val)
- if val.length > 30
- val = val.slice(0..30) + "..."
- end
-
- trace "#{obj_name} => #{val}"
- end
- end
-
- # Turn on trace information when reading a BinData object.
- # If +block+ is given then the tracing only occurs for that block.
- # This is useful for debugging a BinData declaration.
- def trace_reading(io = STDERR)
- @tracer = Tracer.new(io)
- [BasePrimitive, Choice].each(&:turn_on_tracing)
-
- if block_given?
- begin
- yield
- ensure
- [BasePrimitive, Choice].each(&:turn_off_tracing)
- @tracer = nil
- end
- end
- end
-
- def trace_message #:nodoc:
- yield @tracer if @tracer
- end
-
- module_function :trace_reading, :trace_message
-
- class BasePrimitive < BinData::Base
- class << self
- def turn_on_tracing
- alias_method :do_read_without_hook, :do_read
- alias_method :do_read, :do_read_with_hook
- end
-
- def turn_off_tracing
- alias_method :do_read, :do_read_without_hook
- end
- end
-
- def do_read_with_hook(io)
- do_read_without_hook(io)
- trace_value
- end
-
- def trace_value
- BinData.trace_message do |tracer|
- value_string = _value.inspect
- tracer.trace_obj(debug_name, value_string)
- end
- end
- end
-
- class Choice < BinData::Base
- class << self
- def turn_on_tracing
- alias_method :do_read_without_hook, :do_read
- alias_method :do_read, :do_read_with_hook
- end
-
- def turn_off_tracing
- alias_method :do_read, :do_read_without_hook
- end
- end
-
- def do_read_with_hook(io)
- trace_selection
- do_read_without_hook(io)
- end
-
- def trace_selection
- BinData.trace_message do |tracer|
- selection_string = eval_parameter(:selection).inspect
- tracer.trace_obj("#{debug_name}-selection-", selection_string)
- end
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/uint8_array.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/uint8_array.rb
deleted file mode 100644
index 72816611e8eeb..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/uint8_array.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require "bindata/base_primitive"
-
-module BinData
- # Uint8Array is a specialised type of array that only contains
- # bytes (Uint8). It is a faster and more memory efficient version
- # of `BinData::Array.new(:type => :uint8)`.
- #
- # require 'bindata'
- #
- # obj = BinData::Uint8Array.new(initial_length: 5)
- # obj.read("abcdefg") #=> [97, 98, 99, 100, 101]
- # obj[2] #=> 99
- # obj.collect { |x| x.chr }.join #=> "abcde"
- #
- # == Parameters
- #
- # Parameters may be provided at initialisation to control the behaviour of
- # an object. These params are:
- #
- # :initial_length:: The initial length of the array.
- # :read_until:: May only have a value of `:eof`. This parameter
- # instructs the array to read as much data from
- # the stream as possible.
- class Uint8Array < BinData::BasePrimitive
- optional_parameters :initial_length, :read_until
- mutually_exclusive_parameters :initial_length, :read_until
- arg_processor :uint8_array
-
- #---------------
- private
-
- def value_to_binary_string(val)
- val.pack("C*")
- end
-
- def read_and_return_value(io)
- if has_parameter?(:initial_length)
- data = io.readbytes(eval_parameter(:initial_length))
- else
- data = io.read_all_bytes
- end
-
- data.unpack("C*")
- end
-
- def sensible_default
- []
- end
- end
-
- class Uint8ArrayArgProcessor < BaseArgProcessor
- def sanitize_parameters!(obj_class, params) #:nodoc:
- # ensure one of :initial_length and :read_until exists
- unless params.has_at_least_one_of?(:initial_length, :read_until)
- params[:initial_length] = 0
- end
-
- msg = "Parameter :read_until must have a value of :eof"
- params.sanitize(:read_until) { |val| raise ArgumentError, msg unless val == :eof }
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/version.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/version.rb
deleted file mode 100644
index a127d6cb119cf..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/version.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-module BinData
- VERSION = "2.4.15"
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/virtual.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/virtual.rb
deleted file mode 100644
index 1a7205f74bf83..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/virtual.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require "bindata/base"
-
-module BinData
- # A virtual field is one that is neither read, written nor occupies space in
- # the data stream. It is used to make assertions or as a convenient label
- # for determining offsets or storing values.
- #
- # require 'bindata'
- #
- # class A < BinData::Record
- # string :a, read_length: 5
- # string :b, read_length: 5
- # virtual :c, assert: -> { a == b }
- # end
- #
- # obj = A.read("abcdeabcde")
- # obj.a #=> "abcde"
- # obj.c.offset #=> 10
- #
- # obj = A.read("abcdeABCDE") #=> BinData::ValidityError: assertion failed for obj.c
- #
- # == Parameters
- #
- # Parameters may be provided at initialisation to control the behaviour of
- # an object. These params include those for BinData::Base as well as:
- #
- # [:assert] Raise an error when reading or assigning if the value
- # of this evaluated parameter is false.
- # [:value] The virtual object will always have this value.
- #
- class Virtual < BinData::BasePrimitive
-
- def do_read(io)
- end
-
- def do_write(io)
- end
-
- def do_num_bytes
- 0.0
- end
-
- def sensible_default
- nil
- end
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/warnings.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/warnings.rb
deleted file mode 100644
index 3d1cfe728be72..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/bindata-2.4.15/lib/bindata/warnings.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-module BinData
- class Base
- # Don't override initialize. If you are defining a new kind of datatype
- # (list, array, choice etc) then put your initialization code in
- # #initialize_instance. BinData objects might be initialized as prototypes
- # and your initialization code may not be called.
- #
- # If you're subclassing BinData::Record, you are definitely doing the wrong
- # thing. Read the documentation on how to use BinData.
- # http://github.com/dmendel/bindata/wiki/Records
- alias_method :initialize_without_warning, :initialize
- def initialize_with_warning(*args)
- owner = method(:initialize).owner
- if owner != BinData::Base
- msg = "Don't override #initialize on #{owner}."
- if %w(BinData::Base BinData::BasePrimitive).include? self.class.superclass.name
- msg += "\nrename #initialize to #initialize_instance."
- end
- fail msg
- end
- initialize_without_warning(*args)
- end
- alias initialize initialize_with_warning
-
- def initialize_instance(*args)
- unless args.empty?
- fail "#{caller[0]} remove the call to super in #initialize_instance"
- end
- end
- end
-
- class Struct
- # has_key? is deprecated
- alias has_key? key?
- end
-end
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/LICENSE.txt b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/LICENSE.txt
deleted file mode 100644
index eb5808cc171ab..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/LICENSE.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Copyright (c) 2014-2016 Yuki Nishijima
-
-MIT License
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/lib/did_you_mean.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/lib/did_you_mean.rb
deleted file mode 100644
index 2df238da06d66..0000000000000
--- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/did_you_mean-1.6.3/lib/did_you_mean.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-require_relative "did_you_mean/version"
-require_relative "did_you_mean/core_ext/name_error"
-
-require_relative "did_you_mean/spell_checker"
-require_relative 'did_you_mean/spell_checkers/name_error_checkers'
-require_relative 'did_you_mean/spell_checkers/method_name_checker'
-require_relative 'did_you_mean/spell_checkers/key_error_checker'
-require_relative 'did_you_mean/spell_checkers/null_checker'
-require_relative 'did_you_mean/spell_checkers/require_path_checker'
-require_relative 'did_you_mean/spell_checkers/pattern_key_name_checker'
-require_relative 'did_you_mean/formatter'
-require_relative 'did_you_mean/tree_spell_checker'
-
-# The +DidYouMean+ gem adds functionality to suggest possible method/class
-# names upon errors such as +NameError+ and +NoMethodError+. In Ruby 2.3 or
-# later, it is automatically activated during startup.
-#
-# @example
-#
-# methosd
-# # => NameError: undefined local variable or method `methosd' for main:Object
-# # Did you mean? methods
-# # method
-#
-# OBject
-# # => NameError: uninitialized constant OBject
-# # Did you mean? Object
-#
-# @full_name = "Yuki Nishijima"
-# first_name, last_name = full_name.split(" ")
-# # => NameError: undefined local variable or method `full_name' for main:Object
-# # Did you mean? @full_name
-#
-# @@full_name = "Yuki Nishijima"
-# @@full_anme
-# # => NameError: uninitialized class variable @@full_anme in Object
-# # Did you mean? @@full_name
-#
-# full_name = "Yuki Nishijima"
-# full_name.starts_with?("Y")
-# # => NoMethodError: undefined method `starts_with?' for "Yuki Nishijima":String
-# # Did you mean? start_with?
-#
-# hash = {foo: 1, bar: 2, baz: 3}
-# hash.fetch(:fooo)
-# # => KeyError: key not found: :fooo
-# # Did you mean? :foo
-#
-#
-# == Disabling +did_you_mean+
-#
-# Occasionally, you may want to disable the +did_you_mean+ gem for e.g.
-# debugging issues in the error object itself. You can disable it entirely by
-# specifying +--disable-did_you_mean+ option to the +ruby+ command:
-#
-# $ ruby --disable-did_you_mean -e "1.zeor?"
-# -e:1:in `