org.scalautils.PrettyMethods.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalautils_2.11 Show documentation
Show all versions of scalautils_2.11 Show documentation
ScalaUtils is an open-source library for Scala projects that
contains portions of the ScalaTest project that may make sense
to use in production.
The newest version!
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalautils
/**
* Provides an implicit conversion that enables pretty
to be invoked on any
* object, to transform that object into a String
representation.
*/
trait PrettyMethods {
/**
* Wraps a Prettifier
.
*
*
* This class exists so that instances of PrettifierConfig
can be made implicit instead
* of Prettifer
. Because Prettifier
is a Any => String
,
* making it implicit could result in unintentional applications.
*
*
* @param prettifier the configured Prettifier
*/
case class PrettifierConfig(prettifier: Prettifier)
/**
* An implicit PrettifierConfig
that contains a Prettifier.default
.
*
*
* Subclasses can override this method with a different implicit method to have pretty
* use a different Prettifier
.
*
*/
implicit val prettifierConfig = PrettifierConfig(Prettifier.default)
/**
* Implicit class that adds a pretty
method to any object.
*
*
* The constructor of this class, besides taking an object o
to prettify,
* also takes an implicit PrettifierConfig
that the pretty
method will use to prettify the
* object.
*
*
* @param o the object to prettify
* @param prettifierConfig an implicit PrettifierConfig
whose Prettifier
will be used
* to prettify the passed object o
*/
implicit class Prettyizer(o: Any)(implicit prettifierConfig: PrettifierConfig) {
/**
* Returns a pretty String
representation of the object o
*/
def pretty: String = prettifierConfig.prettifier(o)
}
}
/**
* Companion object for trait PrettyMethods
enabling its members to be imported as an
* alternative to mixing them in.
*/
object PrettyMethods extends PrettyMethods
© 2015 - 2025 Weber Informatics LLC | Privacy Policy