Skip to content

Commit

Permalink
Merge pull request #3 from ryan-williams/uri
Browse files Browse the repository at this point in the history
use URI repr as toString
  • Loading branch information
ryan-williams authored Apr 4, 2017
2 parents 5b3ca55 + 9ab8a83 commit b74f864
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name := "paths"
version := "1.0.0"
version := "1.0.1"
deps += libs.value('commons_io)
addScala212
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.7.2")
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.7.3")
16 changes: 12 additions & 4 deletions src/main/scala/org/hammerlab/paths/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Path(val path: JPath)
extends AnyVal
with Serializable {

override def toString: String = path.toString
override def toString: String = uri.toString

def uri: URI = path.toUri

def extension: String = getExtension(path.toString)
def extension: String = getExtension(toString)

def exists: Boolean = Files.exists(path)

Expand Down Expand Up @@ -80,7 +80,7 @@ class Path(val path: JPath)
/**
* Append `suffix` to the basename of this [[Path]].
*/
def +(suffix: String): Path = Path(path.toString + suffix)
def +(suffix: String): Path = Path(toString + suffix)

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

Expand Down Expand Up @@ -108,7 +108,15 @@ class Path(val path: JPath)

object Path {
def apply(path: JPath): Path = new Path(path)
def apply(pathStr: String): Path = new Path(Paths.get(pathStr))

def apply(pathStr: String): Path = {
val uri = new URI(pathStr)
if (uri.getScheme == null)
new Path(Paths.get(pathStr))
else
Path(uri)
}

def apply(uri: URI): Path = new Path(Paths.get(uri))

implicit def toJava(path: Path): JPath = path.path
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/hammerlab/paths/PathTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PathTest
test("extensions") {
"abc.def".extension should be("def")
"/abc/def.gh.ij".extension should be("ij")
"hdfs://foo/bar.baz".extension should be("baz")
"file:///foo/bar.baz".extension should be("baz")
}

test("removals") {
Expand Down

0 comments on commit b74f864

Please sign in to comment.