Page text
◈ PredicateGitHub ↗ Ruby · Rails · Early-stage library Define the rule. Reuse the decision. Move scattered boolean checks into named, composable predicates. Keep your controllers, models, jobs and interfaces aligned around the same business logic. Get startedView source ↗ Predicate.define(:product) do has_name { |s| present?(s[:name]) } in_stock { |s| s[:quantity] > 0 } ready_to_sell do |s| has_name(s) && in_stock(s) end end Predicate.for(:product).call( :ready_to_sell, { name: 'Coffee', quantity: 4 } ) # => true Why Predicate Business rules belong in one place. Composable rules Build larger decisions from small named checks, with boolean combinators and section grouping. Rails integration Expose predicate methods on models and reuse the same decisions in controllers, views and jobs. Evaluation controls State-based caching, optional TTL, thread-safe cache operations and evaluation statistics. One definition, multiple consumers. Input state → Named predicates → Boolean result → Application consumers Use it for onboarding readiness, multi-step forms, checkout requirements and feature eligibility. Keep authorization enforcement in your application's policy boundary. Get started Add the gem to your Gemfile: gem 'predicate-rb' Run bundle install. The library is required as predicate. RubyGems ↗Usage guide ↗Examples ↗ Know how failures behave. By default, missing or failing predicates evaluate to false. Negating that result can produce true. For decisions where evaluation errors must not be silently accepted, use strict mode and handle exceptions explicitly. Include all decision-relevant inputs in cached state. Early-stage software. Predicate grew out of real Rails workflow complexity. Its API is evolving; pin versions and review upgrades. Consult the repository for current licensing and adoption terms. Predicate · Designed for Ruby developers · Repository

Made with Kuickr