Skip to content

Commit

Permalink
Local changes from flight
Browse files Browse the repository at this point in the history
  • Loading branch information
labra committed Oct 6, 2022
1 parent 74d40af commit b185427
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 52 deletions.
58 changes: 7 additions & 51 deletions modules/utils/src/main/scala/es/weso/utils/FileUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import cats.implicits._

object FileUtils {

def getFilesFromFolderWithExt(path: String, ext: String, ignoreFiles: List[String]): IO[List[File]] = IO {
def getFilesFromFolderWithExt(
path: String,
ext: String,
ignoreFiles: List[String]
): IO[List[File]] = IO {
val d = new File(path)
if (d.exists && d.isDirectory) {
d.listFiles.filter { file =>
Expand Down Expand Up @@ -45,36 +49,6 @@ object FileUtils {
(splits.init.mkString("."), splits.last)
}

/** Ensures to close a file. Follows the [[https://wiki.scala-lang.org/display/SYGN/Loan Loan pattern]]
*/
/* def using[A <: { def close(): Unit }, B](resource: A)(f: A => B): B = {
try {
f(resource)
} finally {
resource.close()
}
} */

/** Gets the contents of a file
*
* @param file
* file
*/
/*def getContents(file: File): EitherT[IO, String, CharSequence] = {
try {
using(Source.fromFile(file)("UTF-8")) { source =>
EitherT.pure[IO,String](source.getLines.mkString("\n"))
}
} catch {
case e: FileNotFoundException =>
EitherT.leftT[IO,CharSequence](s"Error reading file ${file.getAbsolutePath}: ${e.getMessage}")
case e: IOException =>
EitherT.leftT[IO,CharSequence](s"IO Exception reading file ${file.getAbsolutePath}: ${e.getMessage}")
case e: Exception =>
EitherT.leftT[IO,CharSequence](s"Exception reading file ${file.getAbsolutePath}: ${e.getMessage}")
}
}*/

/** Gets the contents of a file
*
* @param fileName
Expand All @@ -96,23 +70,7 @@ object FileUtils {
)
with NoStackTrace

/*
def getContents(fileName: String): EitherT[IO, String, CharSequence] = {
try {
using(Source.fromFile(fileName)("UTF-8")) { source =>
EitherT.pure[IO,String](source.getLines.mkString("\n"))
}
} catch {
case e: FileNotFoundException =>
EitherT.leftT[IO,CharSequence](s"Error reading file ${fileName}: ${e.getMessage}")
case e: IOException =>
EitherT.leftT[IO,CharSequence](s"IO Exception reading file ${fileName}: ${e.getMessage}")
case e: Exception =>
EitherT.leftT[IO,CharSequence](s"Exception reading file ${fileName}: ${e.getMessage}")
}
} */

def getStream(fileName: String): Either[String, InputStreamReader] = {
def getStream(fileName: String): Either[String, InputStreamReader] =
try {
val source = Source.fromFile(fileName)("UTF-8")
source.reader().asRight
Expand All @@ -124,7 +82,6 @@ object FileUtils {
case e: Exception =>
Left(s"Exception reading file ${fileName}: ${e.getMessage}")
}
}

/** Write contents to a file
*
Expand All @@ -151,9 +108,8 @@ object FileUtils {
* @return
* String with the line numbers of the char sequence
*/
def formatLines(cs: CharSequence): String = {
def formatLines(cs: CharSequence): String =
cs.toString.linesIterator.zipWithIndex.map(p => (p._2 + 1).toString + " " + p._1).mkString("\n")
}

lazy val currentFolderURL: String =
Paths.get(".").normalize.toUri.toURL.toExternalForm
Expand Down
18 changes: 18 additions & 0 deletions modules/utils/src/main/scala/es/weso/utils/notes/Roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Roadmap

We think that this whole repo should dissapear and be replaced for single purpose repos/components. In order to do that, we will include a list of the modules and potential repos:

## Current modules

- `typing`: Contains a generic `Typing` type class, it can be extracted to its own repo
- `validating`: contains a generic `Checker` trait that has been implemented in Cats. It was originally implemented using the `Eff` library.
- `utilsTest`: this module includes JsonMatchers which are no longer used
- `testSuite`: this module could be extracted as a single repo


The `utils` folder contains the following packages:
- `json`: contains several utilities to work with Json entities in Scala like `DecoderUtils`, `JsonCompare`, `JsonTest` and `JsonTwirl`
- `EitherUtils` contains two helper methods to work with Either values, `sequence` and `takeSingle`
- `FileUtils` contains some helper methods to work with files: `getContents`, `getFileFromFolderWithExt`, `writeFile`, `formatLines`, etc.


2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.7.1

0 comments on commit b185427

Please sign in to comment.