GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rgrabowski/rules_processor: Simple Business Rules Processor

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
lib
lib
 
 
spec
spec
 
 
.codeclimate.yml
.codeclimate.yml
 
 
.gitignore
.gitignore
 
 
.rspec
.rspec
 
 
.rubocop.yml
.rubocop.yml
 
 
.travis.yml
.travis.yml
 
 
Gemfile
Gemfile
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
rules_processor.gemspec
rules_processor.gemspec
 
 

Repository files navigation

Code Climate Test Coverage Issue Count Build Status

Rules Processor

Simple Business Rules Processor.

Installation

Add this line to your application's Gemfile:

gem 'rules_processor'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rules_processor

Configuration

Add to /config/initializers/rules_processor.rb class_name which will be hold actions. This actions will be executed after rule conditions are met.

require 'rules_processor'

RulesProcessor.configure do |config|
  config.actions_class = ::Rule::ActionsProcessor # Example class
end

Usage

Ruleset

Array of rules designed to process. Rules order has importance.

Rule

Rule has conditions and actions. Conditions are grouped in to logical groups: meet_all and meet_any.

Logical group Description
meet_all All conditions in group should match.
meet_any Any condition in group should match.
[
  {
    meet_all: [],
    meet_any: [
        {field: 'ticket_subject', operator: 'include', value: 'return'},
        {field: 'comment_content', operator: 'include', value: 'return'}
    ],
    actions: [
        {action_name: 'ticket_set_priority', value: '1'},
        {action_name: 'ticket_assign_group', value: '3'}
    ]
  }
]

Condition

Conditions has three attributes: :field, :operator, :value

Attribute Description
field Proper construction of field is prefix_ + method_name, when prefix is record's class_name. Example: ticket_subject, ticket_assignee_id, comment_content
operator [List of supported operators] (#supported-operations)
value -

Example condition:

{ field: 'ticket_replies', operator: 'greater_than', value: '6' }

Actions

Action has three attributes :action_name, :value.

Example action:

{ action_name: 'set_status', value: '2' }

How processor works

Public interface:

RulesProcessor::Processor.new(records: {ticket: ticket, comment: comment},
                              options: {},
                              ruleset: ruleset).process

Methods to compare

You can compare against any method which is defined in class of comparable record.

For example if you want to set condition:

{ field: 'ticket_replies', operator: 'greater_than', value: '6' }

Just create method on your record class:

def replies
  replies.size
end

Supported operations

Operator Description
is Equality comparison for string and integers
is_not Equality comparison for string and integers
include Contains at least one of words
not_include Contains none of the words
less_than Compare integers
less_than_equal Compare integers
greater_than Compare integers
greater_than_equal Compare integers

Operators to options for select

There are three groups of operators:

Group Operators
base is, is_not
includable include, not_include
comparable less_than, less_than_equal, greater_than, greater_than_equal

There is a module which returns predefined operators sets.

You can use it in such way:

operators = RulesProcessor::OperatorsToSelect

def ticket_subject_options
  operators.base + operators.includable
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rgrabowski/rules_processor. 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.

License

The gem is available as open source under the terms of the MIT License.

About

Simple Business Rules Processor

Topics

business-rulesrules-enginerules-processor

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.