{"id":16701985,"url":"https://github.com/fatum/business-operation","last_synced_at":"2026-04-24T08:31:09.567Z","repository":{"id":140826547,"uuid":"160904730","full_name":"fatum/business-operation","owner":"fatum","description":"Business logic framework for Ruby/Rails","archived":false,"fork":false,"pushed_at":"2020-02-29T14:56:24.000Z","size":52,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-01T02:39:01.222Z","etag":null,"topics":["ruby","ruby-on-rails","trailblazer"],"latest_commit_sha":null,"homepage":null,"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/fatum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2018-12-08T04:44:18.000Z","updated_at":"2023-01-26T09:49:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"cee52f07-3e8b-4329-ac4b-d87e58977e0e","html_url":"https://github.com/fatum/business-operation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fatum/business-operation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatum%2Fbusiness-operation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatum%2Fbusiness-operation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatum%2Fbusiness-operation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatum%2Fbusiness-operation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatum","download_url":"https://codeload.github.com/fatum/business-operation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatum%2Fbusiness-operation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32216114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T08:24:32.376Z","status":"ssl_error","status_checked_at":"2026-04-24T08:24:26.731Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-on-rails","trailblazer"],"created_at":"2024-10-12T18:46:24.568Z","updated_at":"2026-04-24T08:31:09.536Z","avatar_url":"https://github.com/fatum.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/fatum/business-operation.svg?style=svg)](https://circleci.com/gh/fatum/business-operation)\n\n# Business operation framework\n\n## The main purpose of building this library is creating simple and composable business-logic framework\n\nThe framework is a relatively small and simple (~450 LOC) and mimics Tralblazer Operation API\n\n## Main features\n\n* Simple and concise API using conventions to define handlers\n* We use only keywords for State's keys (it's more convinient). String keys are raising exception\n* You can specify required state's keys for an operation\n* Great traceability: you can trace all your nested execution and see a whole execution tree with options and state\n* Simple integration with `dry-container` gem\n* Handler is a simple class inherited from `Business::Operation::Base` or any callable. No more `Wrap`, `Nested(Operation, input: Input)` from Trailblazer\n\n## Differences between Tralblazer's Operation\n\n* Your handler can be a simple callable object (block, `Proc` or custom class implementing a `.call` method). It lets you easily define small steps like in this example\n\n```ruby\n  class CreateNewUser \u003c Business::Operation::Base\n    step do |state|\n      state[:model] = ModelFinder.factory(state[:params])\n    end\n  end\n```\n\n* Calling an operation registered as a container entry\n\n```ruby\n  Container = Dry::Container.new\n  Container.register(\"users.persister\", Users::Persist)\n\n  class CreateNewUser \u003c Business::Operation::Base\n    container Container\n\n    step \"users.persister\"\n  end\n```\n\n* More concise DSL for wrappers (usable to implement transaction wrapper, exception handlers etc)\n\n```ruby\n  class CreateNewUser \u003c Business::Operation::Base\n    wrap Operation::Transaction, isolation: :serializable do\n      step Users::Persist\n      step Users::AssignAccountManager\n    end\n  end\n```\n\n* Ability to trace an execution tree (`debug: true` option)\n\n```ruby\n  class CreateNewUser \u003c Business::Operation::Base\n    debug true\n    wrap Operation::Transaction, isolation: :serializable do\n      step Users::Persist\n      step Users::AssignAccountManager\n    end\n  end\n```\n\n* Simple and consistent API\n\n```ruby\n  class CreateNewUser \u003c Business::Operation::Base\n    step Operation::Model, class: User\n    step Operation::Pundit, class: TenantPolicy, action: :create_user?\n    step Operation::Contract, class: UserForm, key: :resource\n    wrap Operation::Transaction, isolation: :serializable do\n      step Users::Persist\n      step Users::AssignAccountManager\n    end\n  end\n\n  CreateNewUser.(resource: params, tenant: current_tenant)\n```\n\n* Ability to define requirements for an operation (`depends_on :state, %i[model notifier]`)\n\n```ruby\n  class SendNotification \u003c Business::Operation::Base\n    depends_on :state, %i[model notifier]\n\n    def call\n      notifier = state[:notifier].factory(state[:model])\n      notifier.emit(state[:params])\n    end\n  end\n```\n\n* Clean and understandable source code :). No more magic\n\n```ruby\n  module Business\n    module Operation\n      class Pundit \u003c Base\n        depends_on :state, %i[model params]\n        depends_on :options, %i[class action]\n        depends_on :params, :current_user\n\n        def call(options)\n          current_user = state[:params][:current_user]\n          action = options[:action]\n          policy = options[:class]\n\n          policy.new(current_user, state[:model]).public_send(action)\n        end\n      end\n    end\n  end\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'business-operation'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install business-operation\n\n## Usage example\n\n### Operation creates a new user\n\n```ruby\nrequire \"business/operation\"\nrequire \"business/operation/active_record_transaction\"\nrequire \"dry-container\"\n\nmodule Operation\n  Model = Business::Operation::Model\n  Contract = Business::Operation::Contract\n  Pundit = Business::Operation::Pundit\n  Transaction = Business::Operation::ActiveRecordTransaction\nend\n\n\nclass PublishNewUser \u003c Business::Operation::Base\n  depends_on :state, :model\n\n  def call\n  end\n\n  def self.factory(state)\n    # choose operation\n  end\nend\n\nclass ScheduleEmail \u003c Business::Operation::Base\n  depends_on :state, :model\n\n  def call\n    EmailNotification.create(user: state[:model], type: :signup)\n  end\nend\n\n\nContainer = Dry::Container.new\n\n# Register operation as a container entry\nContainer.register(\"bus.publish_new_user\", PublishNewUser)\n\n# Or use factory block to choose operation on demand\nContainer.register(\"bus.publish_new_user\") { |state| PublishNewUser.factory(state) }\n\nclass CreateUser \u003c Business::Operation::Base\n  container Container\n\n  # Library has some included operations for daily use-cases\n  step Operation::Model, class: User\n  step Operation::Pundit, class: UserPolicy, action: :show?\n  step Operation::Contract,\n       class: UserForm,\n       key: :resource\n\n  # Specify required state entries for next pipeline\n  depends_on :state, %i[model contract]\n\n  # You can wrap batch of operations by wrapper\n  wrap Operation::Transaction do\n    step CreateSubscription\n\n    # You can use previously defined operation\n    step ScheduleEmail\n\n    # You can run failures pipeline if previous step failed\n    # To run only one failure handler specify `fail_fast: true` option\n    failure :cant_schedule_email, fail_fast: true\n\n    # Call earlier registered operation\n    # You may want to make the step being always passing (`fail: false`)\n    step \"bus.publish_new_user\", fail: false\n  end\n\n  failure :failed_notification\n\n  private\n\n  def cant_schedule_email\n    # handler error here\n  end\n\n  def failed_notification\n    # handler error here\n  end\nend\n```\n\n### What handlers you can define\n\nDefining step you can choose between 3 types of handlers\n\n* Another operation class (inherited from `Business::Operation::Base`)\n* Current operation's method (using symbol – `step :call_method`)\n* Operation class registered in dry-container (using string argument – `step \"users.create\"`)\n* Any Proc – `step { |state| state[:key] = \"value\" }`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. 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/fatum/business-operation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Business::Operation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fatum/business-operation/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatum%2Fbusiness-operation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatum%2Fbusiness-operation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatum%2Fbusiness-operation/lists"}