Skip to content

Commit

Permalink
Fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
geirolz committed Jun 30, 2023
1 parent a27f89e commit 5e61b8f
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 29 deletions.
77 changes: 69 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ Given

```scala
import cats.Show
import cats.effect.{ExitCode, Resource, IO, IOApp}
import cats.effect.{Resource, IO}
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.novalues.NoResources
import org.typelevel.log4cats.slf4j.Slf4jLogger

// Define config
case class Config(host: String, port: Int)
Expand All @@ -39,9 +38,7 @@ object Config {
}

// Define service dependencies
case class AppDependencyServices(
kafkaConsumer: KafkaConsumer[IO]
)
case class AppDependencyServices(kafkaConsumer: KafkaConsumer[IO])

object AppDependencyServices {
def resource(res: App.Resources[SimpleAppInfo[String], ToolkitLogger[IO], Config, NoResources]): Resource[IO, AppDependencyServices] =
Expand All @@ -67,11 +64,12 @@ object KafkaConsumer {
}
```

You can write your app as

```scala
import cats.effect.{ExitCode, IO, IOApp}
import com.geirolz.app.toolkit.App
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.error.*

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Expand Down Expand Up @@ -109,11 +107,18 @@ object Main extends IOApp {
libraryDependencies += "com.github.geirolz" %% "toolkit-pureconfig" % "0.0.8"
```

Which allows you to use `withPureConfigLoader` to load the config from a `ConfigSource.default`
Import the syntax

```scala
import com.geirolz.app.toolkit.config.pureconfig.syntax.*
```

Which allows you to use `withPureConfigLoader` to load the config from a `ConfigSource.default`

```scala
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.config.pureconfig.syntax.*

case class TestConfig(value: String)
Expand Down Expand Up @@ -149,4 +154,60 @@ libraryDependencies += "com.github.geirolz" %% "toolkit-log4cats" % "0.0.8"

```sbt
libraryDependencies += "com.github.geirolz" %% "toolkit-odin" % "0.0.8"
```

#### fly4s

```sbt
libraryDependencies += "com.github.geirolz" %% "toolkit-fly4s" % "0.0.8"
```

Import the syntax

```scala
import com.geirolz.app.toolkit.fly4s.syntax.*
```

Which allows you to use `beforeProvidingMigrateDatabaseWithConfig` on `App` to migrate the database before running the
app.
To have access to the whole app dependencies you can use `beforeProvidingMigrateDatabaseWith` instead while to have
access to
the whole app dependencies to provide a custom `Fly4s` instance you can use `beforeProvidingMigrateDatabase`.

```scala
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.fly4s.syntax.*
import com.geirolz.app.toolkit.{App, SimpleAppInfo}

case class TestConfig(dbUrl: String, dbUser: Option[String], dbPassword: Option[Array[Char]])

object TestConfig {
implicit val show: Show[TestConfig] = Show.fromToString
}

App[IO]
.withInfo(
SimpleAppInfo.string(
name = "toolkit",
version = "0.0.1",
scalaVersion = "2.13.10",
sbtVersion = "1.8.0"
)
)
.withConfig(
TestConfig(
dbUrl = "jdbc:postgresql://localhost:5432/toolkit",
dbUser = Some("postgres"),
dbPassword = Some("postgres".toCharArray)
)
)
.withoutDependencies
.provideOne(_ => IO.unit)
.beforeProvidingMigrateDatabaseWithConfig(
url = _.dbUrl,
user = _.dbUser,
password = _.dbPassword
)
.run_
```
77 changes: 69 additions & 8 deletions docs/compiled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ Given

```scala
import cats.Show
import cats.effect.{ExitCode, Resource, IO, IOApp}
import cats.effect.{Resource, IO}
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.novalues.NoResources
import org.typelevel.log4cats.slf4j.Slf4jLogger

// Define config
case class Config(host: String, port: Int)
Expand All @@ -39,9 +38,7 @@ object Config {
}

// Define service dependencies
case class AppDependencyServices(
kafkaConsumer: KafkaConsumer[IO]
)
case class AppDependencyServices(kafkaConsumer: KafkaConsumer[IO])

object AppDependencyServices {
def resource(res: App.Resources[SimpleAppInfo[String], ToolkitLogger[IO], Config, NoResources]): Resource[IO, AppDependencyServices] =
Expand All @@ -67,11 +64,12 @@ object KafkaConsumer {
}
```

You can write your app as

```scala
import cats.effect.{ExitCode, IO, IOApp}
import com.geirolz.app.toolkit.App
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.error.*

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Expand Down Expand Up @@ -109,11 +107,18 @@ object Main extends IOApp {
libraryDependencies += "com.github.geirolz" %% "toolkit-pureconfig" % "0.0.8"
```

Which allows you to use `withPureConfigLoader` to load the config from a `ConfigSource.default`
Import the syntax

```scala
import com.geirolz.app.toolkit.config.pureconfig.syntax.*
```

Which allows you to use `withPureConfigLoader` to load the config from a `ConfigSource.default`

```scala
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.config.pureconfig.syntax.*

case class TestConfig(value: String)
Expand Down Expand Up @@ -149,4 +154,60 @@ libraryDependencies += "com.github.geirolz" %% "toolkit-log4cats" % "0.0.8"

```sbt
libraryDependencies += "com.github.geirolz" %% "toolkit-odin" % "0.0.8"
```

#### fly4s

```sbt
libraryDependencies += "com.github.geirolz" %% "toolkit-fly4s" % "0.0.8"
```

Import the syntax

```scala
import com.geirolz.app.toolkit.fly4s.syntax.*
```

Which allows you to use `beforeProvidingMigrateDatabaseWithConfig` on `App` to migrate the database before running the
app.
To have access to the whole app dependencies you can use `beforeProvidingMigrateDatabaseWith` instead while to have
access to
the whole app dependencies to provide a custom `Fly4s` instance you can use `beforeProvidingMigrateDatabase`.

```scala
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.fly4s.syntax.*
import com.geirolz.app.toolkit.{App, SimpleAppInfo}

case class TestConfig(dbUrl: String, dbUser: Option[String], dbPassword: Option[Array[Char]])

object TestConfig {
implicit val show: Show[TestConfig] = Show.fromToString
}

App[IO]
.withInfo(
SimpleAppInfo.string(
name = "toolkit",
version = "0.0.1",
scalaVersion = "2.13.10",
sbtVersion = "1.8.0"
)
)
.withConfig(
TestConfig(
dbUrl = "jdbc:postgresql://localhost:5432/toolkit",
dbUser = Some("postgres"),
dbPassword = Some("postgres".toCharArray)
)
)
.withoutDependencies
.provideOne(_ => IO.unit)
.beforeProvidingMigrateDatabaseWithConfig(
url = _.dbUrl,
user = _.dbUser,
password = _.dbPassword
)
.run_
```
26 changes: 13 additions & 13 deletions docs/source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ Given

```scala mdoc:silent
import cats.Show
import cats.effect.{ExitCode, Resource, IO, IOApp}
import cats.effect.{Resource, IO}
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.novalues.NoResources
import org.typelevel.log4cats.slf4j.Slf4jLogger

// Define config
case class Config(host: String, port: Int)
Expand All @@ -39,9 +38,7 @@ object Config {
}

// Define service dependencies
case class AppDependencyServices(
kafkaConsumer: KafkaConsumer[IO]
)
case class AppDependencyServices(kafkaConsumer: KafkaConsumer[IO])

object AppDependencyServices {
def resource(res: App.Resources[SimpleAppInfo[String], ToolkitLogger[IO], Config, NoResources]): Resource[IO, AppDependencyServices] =
Expand All @@ -67,11 +64,12 @@ object KafkaConsumer {
}
```

You can write your app as

```scala mdoc:silent
import cats.effect.{ExitCode, IO, IOApp}
import com.geirolz.app.toolkit.App
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.logger.ToolkitLogger
import com.geirolz.app.toolkit.error.*

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Expand Down Expand Up @@ -111,15 +109,16 @@ libraryDependencies += "com.github.geirolz" %% "toolkit-pureconfig" % "@VERSION@

Import the syntax

```scala
```scala mdoc:silent:reset:warn
import com.geirolz.app.toolkit.config.pureconfig.syntax.*
```

Which allows you to use `withPureConfigLoader` to load the config from a `ConfigSource.default`

```scala mdoc:silent

```scala mdoc:silent:reset
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.{App, SimpleAppInfo}
import com.geirolz.app.toolkit.config.pureconfig.syntax.*

case class TestConfig(value: String)
Expand Down Expand Up @@ -165,7 +164,7 @@ libraryDependencies += "com.github.geirolz" %% "toolkit-fly4s" % "@VERSION@"

Import the syntax

```scala
```scala mdoc:silent:reset:warn
import com.geirolz.app.toolkit.fly4s.syntax.*
```

Expand All @@ -175,10 +174,11 @@ To have access to the whole app dependencies you can use `beforeProvidingMigrate
access to
the whole app dependencies to provide a custom `Fly4s` instance you can use `beforeProvidingMigrateDatabase`.

```scala mdoc:silent

```scala mdoc:silent:reset
import cats.Show
import cats.effect.IO
import com.geirolz.app.toolkit.fly4s.syntax.*
import com.geirolz.app.toolkit.{App, SimpleAppInfo}

case class TestConfig(dbUrl: String, dbUser: Option[String], dbPassword: Option[Array[Char]])

Expand Down

0 comments on commit 5e61b8f

Please sign in to comment.