Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1406,15 +1406,6 @@ struct Path
end
end

# Returns a new `URI` with `file` scheme from this path.
#
# A URI can only be created with an absolute path. Raises `Path::Error` if
# this path is not absolute.
def to_uri : URI
raise Error.new("Cannot create a URI from relative path") unless absolute?
URI.new(scheme: "file", path: @name)
end

# Returns the path of the home directory of the current user.
def self.home : Path
new(Crystal::System::Path.home)
Expand Down
13 changes: 13 additions & 0 deletions src/uri.cr
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,16 @@ class URI
end
end
end

struct Path
# Returns a new `URI` with `file` scheme from this path.
#
# A URI can only be created with an absolute path. Raises `Path::Error` if
# this path is not absolute.
#
# NOTE: To use `URI`, you must explicitly import it with `require "uri"`
def to_uri : URI
raise Error.new("Cannot create a URI from relative path") unless absolute?
URI.new(scheme: "file", path: @name)
end
end