Skip to content

Commit

Permalink
Rename set* -> with*
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Nov 7, 2023
1 parent b10646f commit 10eb7fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,27 @@ object InstrumentationScope {
*/
sealed trait Builder {

/** Sets the version.
/** Assigns the version to the scope.
*
* @param version
* the version to set
* the version to assign
*/
def setVersion(version: String): Builder
def withVersion(version: String): Builder

/** Sets the schema URL.
/** Assigns the schema URL to the scope.
*
* @param schemaUrl
* the schema URL to set
* the schema URL to assign
*/
def setSchemaUrl(schemaUrl: String): Builder
def withSchemaUrl(schemaUrl: String): Builder

/** Sets the attributes.
/** Assigns the attributes to the scope.
*
* '''Note''': if called multiple times, only the last specified attributes
* will be used.
*
* @param attributes
* the attributes to set
* the attributes to assign
*/
def setAttributes(attributes: Attributes): Builder

Expand All @@ -110,7 +113,7 @@ object InstrumentationScope {
* the name of the instrumentation scope
*/
def builder(name: String): Builder =
BuilderImpl(name, None, None, Attributes.Empty)
ScopeImpl(name, None, None, Attributes.Empty)

/** Creates an [[InstrumentationScope]].
*
Expand Down Expand Up @@ -151,23 +154,18 @@ object InstrumentationScope {
schemaUrl: Option[String],
attributes: Attributes
) extends InstrumentationScope

private final case class BuilderImpl(
name: String,
version: Option[String],
schemaUrl: Option[String],
attributes: Attributes
) extends Builder {
def setVersion(version: String): Builder =
with Builder {
def withVersion(version: String): Builder =
copy(version = Some(version))

def setSchemaUrl(schemaUrl: String): Builder =
def withSchemaUrl(schemaUrl: String): Builder =
copy(schemaUrl = Some(schemaUrl))

def setAttributes(attributes: Attributes): Builder =
copy(attributes = attributes)

def build: InstrumentationScope =
ScopeImpl(name, version, schemaUrl, attributes)
this
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class InstrumentationScopeSuite extends DisciplineSuite {
.setAttributes(scope.attributes)

val withVersion =
scope.version.fold(builder)(builder.setVersion)
scope.version.fold(builder)(builder.withVersion)

val withResource =
scope.schemaUrl.fold(withVersion)(withVersion.setSchemaUrl)
scope.schemaUrl.fold(withVersion)(withVersion.withSchemaUrl)

assertEquals(withResource.build, scope)
}
Expand Down

0 comments on commit 10eb7fe

Please sign in to comment.