Method: Addressable::URI#path=

Defined in:
lib/addressable/uri.rb

#path=(new_path) ⇒ Object

Sets the path component for this URI.

Parameters:

  • new_path (String, #to_str)

    The new path component.



1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
# File 'lib/addressable/uri.rb', line 1567

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