Method: Addressable::URI#scheme=

Defined in:
lib/addressable/uri.rb

#scheme=(new_scheme) ⇒ Object

Sets the scheme component for this URI.

Parameters:

  • new_scheme (String, #to_str)

    The new scheme component.



917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
# File 'lib/addressable/uri.rb', line 917

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