From 65248d8c09ec1577df34d98e2cdacab3890ec7a7 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 30 Sep 2025 18:30:43 +0800 Subject: [PATCH] Move `Path#to_uri` into `src/uri.cr` --- src/path.cr | 9 --------- src/uri.cr | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/path.cr b/src/path.cr index f87b6f18ab1c..02af385f8e09 100644 --- a/src/path.cr +++ b/src/path.cr @@ -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) diff --git a/src/uri.cr b/src/uri.cr index dc818acf895b..d5452b4bfb05 100644 --- a/src/uri.cr +++ b/src/uri.cr @@ -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