Skip to content

Commit b74f864

Browse files
Merge pull request #3 from ryan-williams/uri
use URI repr as toString
2 parents 5b3ca55 + 9ab8a83 commit b74f864

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name := "paths"
2-
version := "1.0.0"
2+
version := "1.0.1"
33
deps += libs.value('commons_io)
44
addScala212

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.7.2")
1+
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.7.3")

src/main/scala/org/hammerlab/paths/Path.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class Path(val path: JPath)
1313
extends AnyVal
1414
with Serializable {
1515

16-
override def toString: String = path.toString
16+
override def toString: String = uri.toString
1717

1818
def uri: URI = path.toUri
1919

20-
def extension: String = getExtension(path.toString)
20+
def extension: String = getExtension(toString)
2121

2222
def exists: Boolean = Files.exists(path)
2323

@@ -80,7 +80,7 @@ class Path(val path: JPath)
8080
/**
8181
* Append `suffix` to the basename of this [[Path]].
8282
*/
83-
def +(suffix: String): Path = Path(path.toString + suffix)
83+
def +(suffix: String): Path = Path(toString + suffix)
8484

8585
def /(basename: String): Path = Path(path.resolve(basename))
8686

@@ -108,7 +108,15 @@ class Path(val path: JPath)
108108

109109
object Path {
110110
def apply(path: JPath): Path = new Path(path)
111-
def apply(pathStr: String): Path = new Path(Paths.get(pathStr))
111+
112+
def apply(pathStr: String): Path = {
113+
val uri = new URI(pathStr)
114+
if (uri.getScheme == null)
115+
new Path(Paths.get(pathStr))
116+
else
117+
Path(uri)
118+
}
119+
112120
def apply(uri: URI): Path = new Path(Paths.get(uri))
113121

114122
implicit def toJava(path: Path): JPath = path.path

src/test/scala/org/hammerlab/paths/PathTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PathTest
1212
test("extensions") {
1313
"abc.def".extension should be("def")
1414
"/abc/def.gh.ij".extension should be("ij")
15-
"hdfs://foo/bar.baz".extension should be("baz")
15+
"file:///foo/bar.baz".extension should be("baz")
1616
}
1717

1818
test("removals") {

0 commit comments

Comments
 (0)