{"id":22911459,"url":"https://github.com/bytedecoder/onuro","last_synced_at":"2025-05-09T01:33:37.696Z","repository":{"id":56886748,"uuid":"191097637","full_name":"ByteDecoder/onuro","owner":"ByteDecoder","description":"Ruby Workflow Engine based in events that execute a collection of rules","archived":false,"fork":false,"pushed_at":"2023-03-17T01:47:37.000Z","size":60,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T23:48:27.528Z","etag":null,"topics":["ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ByteDecoder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-10T04:39:53.000Z","updated_at":"2024-07-04T03:39:19.000Z","dependencies_parsed_at":"2024-12-14T04:17:01.292Z","dependency_job_id":"27df0b8a-bdbd-4766-a932-22c11c31f525","html_url":"https://github.com/ByteDecoder/onuro","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.018867924528301883","last_synced_commit":"3c4b5923dc108b41830d8dd42e92b2fb9e25d3c3"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDecoder%2Fonuro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDecoder%2Fonuro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDecoder%2Fonuro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDecoder%2Fonuro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ByteDecoder","download_url":"https://codeload.github.com/ByteDecoder/onuro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253174865,"owners_count":21865930,"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":["ruby","ruby-gem"],"created_at":"2024-12-14T04:16:56.541Z","updated_at":"2025-05-09T01:33:37.661Z","avatar_url":"https://github.com/ByteDecoder.png","language":"Ruby","readme":"# Onuro\n\n![Ruby](https://github.com/ByteDecoder/onuro/workflows/Ruby/badge.svg)\n[![Maintainability](https://api.codeclimate.com/v1/badges/adf3d29832220efbd6fc/maintainability)](https://codeclimate.com/github/ByteDecoder/onuro/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/adf3d29832220efbd6fc/test_coverage)](https://codeclimate.com/github/ByteDecoder/onuro/test_coverage)\n![License](https://img.shields.io/badge/license-MIT-green)\n\nWorkflow Engine based in events that execute a collection of rules defined in the event configuration definition\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```bash\ngem 'onuro'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install onuro\n\n## Usage\n\nThe easiest way to load *Events + Rules* configuration in the **Engine** is using the configuration blocks. Its important to mention these global pre-configured events, would not be changed when in runt-time an **engine instance** is begin fetched with new events.\n\n```ruby\nclass Rule1 \u003c Onuro::BaseRule; end\nclass Rule2 \u003c Onuro::BaseRule; end\nclass Rule3 \u003c Onuro::BaseRule; end\nclass MyCustomEventStrategy \u003c Onuro::DefaultEventStrategy\n  # override here the methods to execute your custom logic before/after each rule\nend\n\n# Onuro::Engine configuration block\nOnuro::Engine.configure do |config|\n  config.add_event(:event_one) do |event|\n    event.add_ruleset_stage [\n      Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1),\n      Onuro::RuleStage.new(rule: Rule3, enabled: true, order: 2)\n    ]\n    event.add_event_strategy(MyCustomEventStrategy.new)\n    event.exec_order(:desc)\n    event.ignore_diseabled\n  end\n\n  config.add_event(:event_two) do |event|\n    event.add_ruleset_stage [\n      Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1),\n      Onuro::RuleStage.new(rule: Rule2, enabled: true, order: 2)\n    ]\n  end\n\n  config.add_event(:event_three) do |event|\n    event.add_ruleset_stage [Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1)]\n  end\n\n  config.add_event(:event_four) do |event|\n    event.add_ruleset_stage Onuro::RuleStage.default_ruleset_stage_factory([Rule1, Rule2, Rule3])\n  end\nend\n\n# When the *engine object is created, will fetch the pre-configured events for instant use,\n# saving the boilerplate object setup for your common events and rule sets.\nexec_result = Onuro::Engine.new.execute(:event_four)\n```\n\n### Context\n\nThis is the instance object that will be passed through all the event execution process. Here you can pass key/value params that will be help you while the **Rules** are being executed. Things like *member_id*, *current_date* (you name it) will be passed from the engine to all the way down until the end of the execution. Since is a reference object, you can add new key/value states during the *ruleset* execution.\n\nOne way:\n```ruby\nOnuro::Engine.new.execute(:my_event) do |context|\n  context.add(:member_id, 1)\n  context.add(:current_date, '01/01/2019')\nend\n```\n\nAnother way:\n```ruby\ncontext = Onuro::ContextBuilder.build do |context|\n    context.add(:member_id, 1)\n    context.add(:current_date, '01/01/2019')\nend\n\nOnuro::Engine.new.execute(:my_event, context)\n```\n\nAnother way with *double splat* operators in the *Context* constructor:\n```ruby\ncontext = Onuro::Context.new(member_id: 1, current_date: '01/01/2019')\n\nOnuro::Engine.new.execute(:my_event, context)\n```\n\n**Note:** If you do not provide a context, an empty one will be created.\n\n### Engine\n\nThe **engine** is the object that can hold a list of **events**, where the desired **event** is executed and additionally, you can provide a **context** object with helpful key/value data that will help you in your **rule** processing.\n\n```ruby\ncontext = Onuro::Context.new(...your data..)\nengine = Onuro::Engine.new\n\nengine.add_events([event1, event2])\nengine.new.execute(:my_event, context)\n```\n\n### Rules\n\nAre the foundation building blocks of the *rulesets* and this is where you can place your **logic** divided in segments(**rules**).\n\nAll the rules processed by the engine is recommended to inherith from **Onuro::BaseRule** since this base class give you access to the **logger** support and easy access to the **ExecutionResult** constants used by the engine. Basically you need to override/implement **execute** method accepting as input an **context** object. The **rule** need to return and **ExecutionResult** constant. (More about extending this later in this README)\n\nA collection of *rules* is holded by an **event** object\n\n```ruby\nclass MyRule \u003c Onuro::BaseRule\n  def execute(context)\n    context[:mul_result] = context[:first_operand] * context[:second_operand]\n    SUCCESSFUL\n  end\nend\n\nruleset_stage = Onuro::RuleStage.default_ruleset_stage_factory([MyRule])\nevent.add_ruleset_stage(ruleset_stage)\n```\n\nAlso, you can execute a single rule without using the full **Onuro::Engine**\n\n```ruby\nMyRule.new.execute(context)\n```\n\n### RuleStage\n\nSince *Onuro* allows the rule execution, you can diseable or add a particular **order** of execution to all the rules in a rulseset, the **RuleStage** class help us to do that. You cannot add the **Rule** object instances directly in the event, without adding first each rule into a **RuleStage** object.\n\n```ruby\nevent.add_ruleset_stage [\n  Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1),\n  Onuro::RuleStage.new(rule: Rule3, enabled: true, order: 2)\n]\n```\n\nIf you want to add all the rules enabled by default, and the execution order will be based in the order that you define the ruleset collection, you can use a **RuleStage** factory to save all these object setup:\n\n```ruby\nevent.add_ruleset_stage Onuro::RuleStage.default_ruleset_stage_factory([Rule1, Rule2, Rule3])\n```\n\n### Events\n\nEvents are the component that hold an *rulset stage* composed of a list of rules and their settings for execution. The easiest way to define and event is creating the instance object always with the event name required. In order to create complex events with more settings, take a look to the *Event Builder* section.\n\n```ruby\nevent = Onuro::Event.new(:my_event)\nengine.add_event(event)\nengine.execute(:my_event)\n```\n\n### Event Builder\n\nAn easier way to create an event, is using the **EventBuilder** class based on the *builder pattern*. This gives a lot of flexibility when you are creating the events and avoid having a lot or parameters in the constructor and assembling  all the event internals, and easy to to be plugged in you **Engine** class instance.\n\n```ruby\nevent = Onuro::EventBuilder.build(:test_ruleset) do |builder|\n          builder.add_ruleset_stage([rule1, rule2, rule3])\n          builder.add_event_strategy(MyCustomEventStrategy.new)\n          builder.exec_order(:desc)\n          buidler.ignore_diseabled\n        end\n\nengine.add_event(event)\nengine.execute(:test_ruleset)\n```\n\n### Event Strategies\n\nEvents allow you to implement your custom strategy, to control what happens before and after the rule is executed in the event. By default Onuro provides a default strategy:\n\n```ruby\nmodule Onuro\n  class DefaultEventStrategy\n    def before_rule_exec(_rule_stage, _context)\n      true\n    end\n\n    def after_rule_exec(_rule_stage, _context, _result)\n      true\n    end\n  end\nend\n```\n\nYou only need to implement the methods **before_rule_exec** and **after_rule_exec** in your custom class returning a boolean value. Basically, this is the *strategy pattern*.\n\nIf **before_rule_exec** returns false, skip the current rule execution and move to the next one in the ruleset list.\n\n### ExecutionResult\n\nTBD\n\n### Determining succcess or failure of the event processing\n\nTBD\n\n### Logging\n\nTBD\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ByteDecoder/onuro.\n\n\nCopyright (c) 2019 [Rodrigo Reyes](https://twitter.com/bytedecoder) released under the MIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedecoder%2Fonuro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedecoder%2Fonuro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedecoder%2Fonuro/lists"}