[keygenerator] Extract as a trait

This commit is contained in:
Paul Campbell 2019-05-09 18:33:29 +01:00
parent b348f18142
commit 6af5b8cafc
2 changed files with 15 additions and 8 deletions

View file

@ -0,0 +1,14 @@
package net.kemitix.s3thorp
import java.io.File
trait KeyGenerator {
def generateKey(c: Config)(file: File): String = {
val otherPath = file.toPath.toAbsolutePath
val sourcePath = c.source.toPath
val relativePath = sourcePath.relativize(otherPath)
s"${c.prefix}/$relativePath"
}
}

View file

@ -6,14 +6,7 @@ import fs2.Stream
import cats.effect.IO import cats.effect.IO
import net.kemitix.s3thorp.awssdk.S3Client import net.kemitix.s3thorp.awssdk.S3Client
trait S3MetaDataEnricher extends S3Client { trait S3MetaDataEnricher extends S3Client with KeyGenerator {
def generateKey(c: Config)(file: File): String = {
val otherPath = file.toPath.toAbsolutePath
val sourcePath = c.source.toPath
val relativePath = sourcePath.relativize(otherPath)
s"${c.prefix}/$relativePath"
}
def enrichWithS3MetaData(c: Config): File => Stream[IO, Either[File, S3MetaData]] = { def enrichWithS3MetaData(c: Config): File => Stream[IO, Either[File, S3MetaData]] = {
val fileToString = generateKey(c)_ val fileToString = generateKey(c)_