Skip to content

Commit

Permalink
add ops
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Oct 7, 2018
1 parent dc763ad commit 8ede858
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name := "paths"
v"1.5.1"
v"1.6.0"
dep(
case_app,
commons.io,
hammerlab.types % "1.4.0",
slf4j
)
testDeps := Seq(
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.5
sbt.version=1.2.3
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" % "base" % "4.5.1")
addSbtPlugin("org.hammerlab.sbt" % "base" % "4.6.5")
25 changes: 21 additions & 4 deletions src/main/scala/org/hammerlab/paths/HasPathOps.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package org.hammerlab.paths

import java.io.FileNotFoundException

import hammerlab.either._
import hammerlab.str._

trait HasPathOps {
implicit val makePathSymbolOps = HasPathOps.PathSymbolOps _
implicit val makePathStringOps = HasPathOps.PathStringOps _
implicit val makePathOps = HasPathOps.PathOps _
}

object HasPathOps {
implicit class PathSymbolOps(val s: Symbol) extends AnyVal {
def /(t: String): Path = Path(s.name) / t
def /(t: Symbol): Path = Path(s.name) / t
def / (t: Str): Path = Path(s.name) / t
}
implicit class PathStringOps(val s: String) extends AnyVal {
def /(t: String): Path = Path(s) / t
def /(t: Symbol): Path = Path(s) / t
def / (t: Str): Path = Path(s) / t
}
implicit class PathOps(val dir: Path) extends AnyVal {
def ?(basename: Str): FileNotFoundException | Path = {
val path = dir / basename
if (!path.exists)
Left(
new FileNotFoundException(
path.toString
)
)
else
Right(path)
}
}
}

0 comments on commit 8ede858

Please sign in to comment.