From 6af5b8cafc6c0a5f81411914e0a498c5e7314e40 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 9 May 2019 18:33:29 +0100 Subject: [PATCH] [keygenerator] Extract as a trait --- .../scala/net/kemitix/s3thorp/KeyGenerator.scala | 14 ++++++++++++++ .../net/kemitix/s3thorp/S3MetaDataEnricher.scala | 9 +-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 src/main/scala/net/kemitix/s3thorp/KeyGenerator.scala diff --git a/src/main/scala/net/kemitix/s3thorp/KeyGenerator.scala b/src/main/scala/net/kemitix/s3thorp/KeyGenerator.scala new file mode 100644 index 0000000..fa6ca40 --- /dev/null +++ b/src/main/scala/net/kemitix/s3thorp/KeyGenerator.scala @@ -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" + } + +} diff --git a/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala index e8fb83e..153fc23 100644 --- a/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala +++ b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala @@ -6,14 +6,7 @@ import fs2.Stream import cats.effect.IO import net.kemitix.s3thorp.awssdk.S3Client -trait S3MetaDataEnricher extends S3Client { - - 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" - } +trait S3MetaDataEnricher extends S3Client with KeyGenerator { def enrichWithS3MetaData(c: Config): File => Stream[IO, Either[File, S3MetaData]] = { val fileToString = generateKey(c)_