enclosure


License

License

GroupId

GroupId

com.lorandszakacs
ArtifactId

ArtifactId

enclosure_3
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

enclosure
enclosure
Project URL

Project URL

https://github.com/lorandszakacs/enclosure
Project Organization

Project Organization

Loránd Szakács
Source Code Management

Source Code Management

https://github.com/lorandszakacs/enclosure

Download enclosure_3

How to add to project

<!-- https://jarcasting.com/artifacts/com.lorandszakacs/enclosure_3/ -->
<dependency>
    <groupId>com.lorandszakacs</groupId>
    <artifactId>enclosure_3</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.lorandszakacs/enclosure_3/
implementation 'com.lorandszakacs:enclosure_3:0.1.2'
// https://jarcasting.com/artifacts/com.lorandszakacs/enclosure_3/
implementation ("com.lorandszakacs:enclosure_3:0.1.2")
'com.lorandszakacs:enclosure_3:jar:0.1.2'
<dependency org="com.lorandszakacs" name="enclosure_3" rev="0.1.2">
  <artifact name="enclosure_3" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.lorandszakacs', module='enclosure_3', version='0.1.2')
)
libraryDependencies += "com.lorandszakacs" % "enclosure_3" % "0.1.2"
[com.lorandszakacs/enclosure_3 "0.1.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala3-library_3 jar 3.0.0

Project Modules

There are no modules declared in this project.

enclosure

Simple macro to generate an case class Enclosure(fullModuleName: String) data-type telling you in which module it was instantiated in. Think, log4s or log4cats logger names based on the class/object/trait they were created in, but generalized and useable outside of that context.

Honestly, the library should be pretty stable and will most likely change only to support new Scala versions. But what do I know?

getting started

This library is published for Scala 3.0.0, 2.13, 2.12, both on the JVM and JS platforms.

libraryDependencies ++= "com.lorandszakacs" %% "enclosure" % "0.1.2"

usage

This library provides one single type: com.lorandszakacs.enclosure.Enclosure which simply contains the fully qualified name of the enclosing module. Where module is either one of:

  • class
  • object
  • package (object)

Simply add an implicit parameter to your methods/classes, and a macro will generate a value for Enclosure for you.

Similar in usage to munit.Location, or org.tpolecat.SourcePos.

package myapp
import com.lorandszakacs.enclosure.Enclosure

object Printer {
  def locatedPrintln(s: String)(implicit enc: Enclosure): Unit =  {
    println(s"[${enc.fullModuleName}] $s")
  }
}

// -------
package myapp.module

object Main extends App {
  myapp.Printer.locatedPrintln("in main!")
  // prints out:
  // [myapp.module.Main] in main!
  nestedMethod()
  // idem

  def nestedMethod(): Unit = {
    myapp.Printer.locatedPrintln("in main!")
  }
}

motivation

The library was created to generalize, and make available to end-users, the log4s, log4cats logger name from enclosing class behavior. But it can obviously find itself other usages now as well.

Versions

Version
0.1.2