All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skinny.micro.async.AsyncBeforeAfterDsl.scala Maven / Gradle / Ivy

package skinny.micro.async

import skinny.micro.{ Context, RouteTransformer }
import skinny.micro.base.{ SkinnyContextInitializer, RouteRegistryAccessor }
import skinny.micro.routing.Route

/**
 * Before/After DSL for Async web apps.
 */
trait AsyncBeforeAfterDsl { self: RouteRegistryAccessor with SkinnyContextInitializer =>

  /**
   * Adds a filter to run before the route.  The filter only runs if each
   * routeMatcher returns Some.  If the routeMatchers list is empty, the
   * filter runs for all routes.
   */
  def before(transformers: RouteTransformer*)(fun: (Context) => Any): Unit = {
    routes.appendBeforeFilter(Route(transformers, () => fun(context)))
  }

  /**
   * Adds a filter to run after the route.  The filter only runs if each
   * routeMatcher returns Some.  If the routeMatchers list is empty, the
   * filter runs for all routes.
   */
  def after(transformers: RouteTransformer*)(fun: (Context) => Any): Unit = {
    routes.appendAfterFilter(Route(transformers, () => fun(context)))
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy