GithubHelp home page GithubHelp logo

jrudolph / recursivity-commons Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bowler-framework/recursivity-commons

2.0 3.0 1.0 219 KB

Common utility classes and simple validation framework, built with sbt (simple-build-tool)

License: BSD 3-Clause "New" or "Revised" License

Java 13.58% Scala 86.42%

recursivity-commons's Introduction

Recursivity-commons utilities

Various Java- and Scala utilities with no outside library dependencies. Built with SBT (Simple-Build-Tool)

Java classes: not written by me, but stuff I often use and compiled from various books and open source sources.

MVN/SBT repo:

https://oss.sonatype.org/content/repositories/releases (built against 2.9.0-1, compatible with Scala 2.8.x, but requires you to build yourself)

Dependency definition (sbt):

"com.recursivity" %% "recursivity-commons" % "0.5.5"

Scala validator (com.recursivity.commons.validator-package)

Simple and extensible Scala validation framework that makes use of Scala function passing to provide a more powerful validation framework. Supports:

  • Custom validators
  • Localised error messages
  • hooking in at various level of granularity, depending on your needs.

Example usage:

// setup a bean to validate
val bean = new MyBean("hello", 5, new Date, None)

// new ValidationGroup with a ClassPathMessageResolver
val group = ValidationGroup(new ClasspathMessageResolver(this.getClass))

// add the validators to the ValidationGroup, note how we pass an anonymous function that will get the value/variable we want to validate.
group.add(MinLength("hello", 8, {bean.text}))
group.add(MaxInt("max", 3, {bean.number}))
group.add(MinInt("min", 6, {bean.number}))
group.add(NotNullOrNone("null", {bean.value}))

// validate and return error messages, a List of Tuple2's with (key, errorMessage) format.
val failures = group.validateAndReturnErrorMessages

Assumes property-files in the same package with the same name as "this"-class, for instance com.mypackage.MyClass would be:

/com/mypackage/MyClass.properties // for the default messages
/com/mypackage/MyClass_se.properties // for messages localized in Swedish

Contents of property-file might be:

#Validator messages
MinLengthValidator={key} must be at least {min} characters long
# {key} is replaced for either property value of key, for instance "hello", or simply the raw key.
# {min} in this example would be replaced by 8 from the code above.

# property key-values
hello='your text'

recursivity-commons's People

Contributors

aloiscochard avatar oletraveler avatar viktorklang avatar wfaler avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

oloed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.