
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
= Rule
== What is it?
Rule is a state machine / rule engine. It does things.
== How do I get started?
Add it to your gemfile.
gem "rule", :git => "https://github.com/innovatis/rule"
Add a "state" column and this code to your model:
rule_engine MyAwesomeRuleEngine
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
Create a file at app/rules/is_in_progress_rule.rb
class IsInProgressRule < Rule::Base def validate @object.in_progress.present? end end
Set your application up to run the rules.
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
Unknown package
We found that rule demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.