Skip to content

Guide

Welcome to the Ruleur guide! This section provides comprehensive documentation on all features and capabilities.

Core Concepts

DSL Basics

Learn the Ruby DSL for defining rules, including all helper methods and shortcuts.

Conditions

Master composable conditions with all/any/not operators and predicate logic.

Operators

Explore all available comparison and logical operators.

Rule Authoring

YAML Rules

Define rules in YAML format for database storage and runtime loading.

Validation

Validate rules before execution with structural, semantic, and test validation.

Persistence & Versioning

Persistence

Store rules in memory or database using repositories.

Versioning & Audit

Track rule changes with full audit trails and rollback support.

Advanced Topics

Advanced Topics

Salience, no-loop, tracing, and performance optimization.

Quick Reference

Common Patterns

ruby
# Permission check
conditions do
  any?(user(:admin?), record(:public?))
end

# Ownership check
conditions do
  all?(
    eq?(record_value(:owner_id), user_value(:id)),
    record(:active?)
  )
end

# Range check
conditions do
  all?(
    gte?(record_value(:price), 100),
    lte?(record_value(:price), 1000)
  )
end

# Array membership
includes(record_value(:roles), literal('editor'))

# Pattern matching
matches(record_value(:email), literal(/\A[\w+\-.]+@[a-z\d-]+(\.[a-z\d-]+)*\.[a-z]+\z/i))

DSL Reference

MethodDescriptionExample
user(:admin?)Predicate on user objectuser(:admin?)
record(:active?)Predicate on record objectrecord(:active?)
user_value(:id)Get field value from useruser_value(:id)
record_value(:owner_id)Get field value from recordrecord_value(:owner_id)
flag(:create)Check if permission grantedflag(:create)
set :update, trueGrant permissionset :update, true

Operators Reference

Comparison:

  • eq?(a, b) - Equal
  • not_eq?(a, b) - Not equal
  • gt?(a, b) - Greater than
  • gte?(a, b) - Greater than or equal
  • lt?(a, b) - Less than
  • lte?(a, b) - Less than or equal

Logical:

  • truthy?(value) - Value is truthy
  • falsy?(value) - Value is falsy
  • present?(value) - Value is present (not nil/empty)
  • blank?(value) - Value is blank (nil/empty)

Collections:

  • in?(value, array) - Value in array
  • contains?(array, value) - Array contains value

Patterns:

  • matches(string, regex) - String matches regex

Released under the MIT License.