This gem provides classes to create arbitrary complex conditions, by building an expression tree. Currently only basic operations are implemented.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install criteria_operator
For complete usage information, read the docs!
All relevant classes inherit from
BaseOperator. Generally, you'll want to have a root node of this type, which will in turn contain the whole expression tree. Currently, there are the following operators:
BinaryOperator is the most commonly used. It represents a binary operation, meaning an operator with a left and right hand side operand, each. The operands can be any
BaseOperator. The operator has to be one of the following types:
- Equal (default)
- Not Equal
- Greater or Equal
- Less or Equal
These types are represented by constants in the module
# checks if the operands op1 and op2 are different operator = ::. op1, op2, ::::
GroupOperator is used to connect an amount of conditions (
BaseOperators) with either
AND (default) or
# checks if any of the conditions represented by operands op1 through op3 is true operator = ::. [op1, op2, op3], ::::
UnaryOperator is used to perform simple checks or transform a value represented by an operand (
BaseOperator). It takes on operand as well and has one of the following types:
- NOT (default)
- IS NULL
These types can be found in the
# invert the sign of the result returned by operand op1 operator = ::. op1, ::::
OperandProperty is, as the name implies, an operand. This means, it does not work with any other operands like operators do. If presented as a tree, operands always are leaves. The
OperandProperty describes a property through it's name.
# represents a column named 'integer_value' (without quotes) operand = ::. 'integer_value'
OperandValue is, just like the
OperandProperty, an operand. It represents any kind of value.
# represents the numeric value forty-two operand = ::. 42
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake test to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/TheFlow0360/criteria_operator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Prerequisite to the acceptance of any pull requests is a successful build (this will be checked automatically) as well as test coverage and complete documentation.
The gem is available as open source under the terms of the MIT License.