Sha256: 468dc010915f7361afdee896ef7ffed105391b29976fb988663776a3681d4958
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
AR Rules ========= A Ruby gem engine that allows you to add customizable business rules to any ActiveRecord model. Rules integrates with ActiveAdmin to make it trivial to allow admin users to create rules on the fly for your models. Installation ------------ Add it to your Gemfile: ```ruby gem "rules", :github => 'azach/rules' ``` Update your schema: ```ruby rake rules:install:migrations rake db:migrate ``` to create the required tables to store your rules. Setting Up Rules ------------ To use rules on a model, include ```Rules::HasRules```. You can also optionally define any attributes that are available for that model using ```has_rule_attributes```. This will allow the user to build rules against this attribute. For example, you may want to allow users to build rules against the email address in the order. In this case, your model would look like: ```ruby class Order < ActiveRecord::Base include Rules::HasRules has_rule_attributes({ customer_email: { name: "customer email address" } }) end ``` To evaluate a set of a rules, use the ```rules_pass?``` method on the instance. You may also pass the values of the attributes that you allowed users to define rules against at this point. For example: ```ruby order = Order.new order.email_address = "morbo@example.com" order.evaluate(customer_email: order.email_address) ``` Defining Rules ------------ Rules are meant to be defined by business users using an admin interface. For this reason, the gem provides integration with ActiveAdmin to make this easier. There are two helper methods you can use, one for your show action and one for your form. For the show action: ```ruby show_rules ``` For the form action: ```ruby f.has_rules ``` This will give you something like: ![ActiveAdmin form for editing rules](https://github.com/azach/rules/raw/master/spec/dummy/app/assets/images/edit_example.png) Default Constants ------------ TODO Default Evaluators ------------ TODO
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rules-0.0.1 | README.md |