{"id":20407830,"url":"https://github.com/restorando/rbrules","last_synced_at":"2025-07-03T08:34:31.192Z","repository":{"id":15031026,"uuid":"17756841","full_name":"restorando/rbrules","owner":"restorando","description":"Declare rule sets to check your objects against them later","archived":false,"fork":false,"pushed_at":"2015-09-01T14:14:09.000Z","size":211,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-04-12T15:36:22.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"eSDK/esdk_tp_wsdl","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/restorando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-14T19:01:35.000Z","updated_at":"2020-10-21T20:21:46.000Z","dependencies_parsed_at":"2022-08-29T03:00:37.823Z","dependency_job_id":null,"html_url":"https://github.com/restorando/rbrules","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/restorando/rbrules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restorando%2Frbrules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restorando%2Frbrules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restorando%2Frbrules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restorando%2Frbrules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/restorando","download_url":"https://codeload.github.com/restorando/rbrules/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restorando%2Frbrules/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263290964,"owners_count":23443688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T05:26:26.877Z","updated_at":"2025-07-03T08:34:31.157Z","avatar_url":"https://github.com/restorando.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RbRules\n\nThis library simplifies a rule set definition that can later be used to check if they\nare satisfied for a given object or to find the rule that a given object doesn't satisfy.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'rbrules'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rbrules\n\n## Usage\n\nDefine your ruleset:\n\n```ruby\nMY_HOUSE_MY_RULES = RbRules.new do |rules|\n  rules.rule(:smoke) { |age| age \u003e 21 }\n  rules.rule(:sleep) { |age| age.even? }\nend\n```\n\nTest your object\n\n```ruby\nMY_HOUSE_MY_RULES.all? 22 # =\u003e true\nMY_HOUSE_MY_RULES.none? 12 # =\u003e false\n```\n\nIf you don't want to pollute your global namespace to define global rules, you can give\nyour a name to your rule set like this:\n\n```ruby\nRbRules[:salute].rule(:hawaiian) {|string| string =~ /aloha/i }\nRbRules[:salute].rule(:english) {|string| string =~ /hello|good bye/i }\n\nRbRules[:salute].any? \"Aloha world!\"\n```\n\nYou can also define your custom rules (which should respond to `#call(obj)`) in case\nyou need to take different actions when different rules fail\n\nFor example:\n\n```ruby\nclass MagicNumber \u003c Struct.new(:magic_number)\n\n  def call(obj)\n    magic_number == obj\n  end\n\nend\n\nRbRules[:random_rules].rule MagicNumber.new(3)\n\nmatching_rule = RbRules[:random_rules].any?(3)\nmatching_rule.magic_number # =\u003e 3\n```\n\nAdding new rules to an existing one\n\nYou can add new rules to existing ones using the `ruby + ` operator.\n\n```ruby\nnew_rule = RbRules.new do |rules|\n   rules.rule(:alive) { |age| age \u003c 1000 }\nend\n\nNEW_HOUSE_RULES = MY_HOUSE_MY_RULES + new_rule\n\nNEW_HOUSE_RULES.all? 19 # =\u003e false\nNEW_HOUSE_RULES.all? 22 # =\u003e false\nNEW_HOUSE_RULES.any? 95 # =\u003e true\nNEW_HOUSE_RULES.all? 94 # =\u003e true\n```\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestorando%2Frbrules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frestorando%2Frbrules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestorando%2Frbrules/lists"}