New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rule

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rule

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Rule

== What is it?

Rule is a state machine / rule engine. It does things.

== How do I get started?

  1. Add it to your gemfile.

    gem "rule", :git => "https://github.com/innovatis/rule"

  2. Add a "state" column and this code to your model:

    rule_engine MyAwesomeRuleEngine

  3. create a file at app/rule_engines/my_awesome_rule_engine.rb

    class MyAwesomeRuleEngine < Rule::Engine::Base

    state :new state :ongoing state :closed

    initial_state :new

    terminal_state :closed

    transition :new, :ongoing validate IsInProgressRule end

    transition :ongoing, :closed assert_presence_of object.closed_at, "Closed At" end

    end

  4. Create a file at app/rules/is_in_progress_rule.rb

    class IsInProgressRule < Rule::Base def validate @object.in_progress.present? end end

  5. Set your application up to run the rules.

    wherever it makes sense...

    my_object.run_rules # advances state as far as possible and automatically saves

== Explain all that stuff.

Okay.

The Rule::Engine::Base subclass defines states and transitions. Each transition block contains a number of assertions and an optional priority. If any of the assertions does not pass, the state will not follow this transition. The priority decides which transition to use in the case of two possible transitions out of the current state both being valid. Use it by specifying "priority :high" or "priority :low" in the transition block.

It often makes sense to bundle a group of assertions into a Rule class. These are defined in app/rules, and have a validate method containing assertions. In the future, rules will also have callbacks that fire when the state is advanced through a transition including that rule.

If this didn't answer your questions, throw things at Burke until he explains.

== Copyright

Copyright (c) 2011 Burke Libbey / Innovatis. MIT License.

FAQs

Package last updated on 21 Oct 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc