A C++ library for structuring business rules.
Structuring and validating business rules in JavaScript
The essential part of the library is a specification -- an object with the following properties:
- it can be combined with other specification-objects using
.And()
,.Or()
and.Not()
methods to form a composite specification and express more complex rules. - it implements
is_satisfied_by
method -- a predicate that determines whether a candidate object does or does not satisfy some criteria.
To create a specification:
- create a new class that inherits
basic_spec<T>
. - override the
clone
method to allow copying. - override the
is_satisfied_by
method.
the and of a set of specifications is true if and only if all of its operands are true.
auto spec = spec1.And(spec2);
the or of a set of specifications is true if and only if one or more of its operands is true
auto spec = spec1.Or(spec2);
not negates the specification
auto spec = spec1.Not();
checks whether some candidate object satisfies the specification.
auto result = spec.is_satisfied_by(obj);
// `result` true|false value
// should throw an exception in case of an error
- Linux (x86/64)
- GCC 5.1
- Clang 3.7
This is a header only library, in order to use it make the bspec-include
directory available to your project and include the header file in your source code:
#include "bspec/spec.h"
This project tests and examples use the Cross-platform Make (CMake) build system. Tests depend on Google Test Framework. gtest-1.7.0 is recommended.
The recommended way is to create 'out of source' build:
mkdir build
cd build
cmake ..
make
[Grigoriy Chudnov] (mailto:g.chudnov@gmail.com)
Distributed under the The MIT License (MIT).