{"id":28865295,"url":"https://github.com/magdielcardoso/active_act","last_synced_at":"2026-03-18T02:35:28.310Z","repository":{"id":298402811,"uuid":"999876687","full_name":"magdielcardoso/active_act","owner":"magdielcardoso","description":"Abstract spare methods from your controllers and models into actions in Ruby with Active Act 🚀","archived":false,"fork":false,"pushed_at":"2025-06-12T17:24:47.000Z","size":84,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-29T13:15:09.272Z","etag":null,"topics":["open-source","rails","ruby","ruby-gem","ruby-on-rails","rubygem"],"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/magdielcardoso.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":["magdielcardoso"]}},"created_at":"2025-06-10T23:45:56.000Z","updated_at":"2025-06-14T03:01:11.000Z","dependencies_parsed_at":"2025-06-11T00:11:36.712Z","dependency_job_id":"e2bc8fc2-5ab1-4641-b9a0-cfecc94b752a","html_url":"https://github.com/magdielcardoso/active_act","commit_stats":null,"previous_names":["magdielcardoso/active_act"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/magdielcardoso/active_act","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magdielcardoso%2Factive_act","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magdielcardoso%2Factive_act/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magdielcardoso%2Factive_act/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magdielcardoso%2Factive_act/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magdielcardoso","download_url":"https://codeload.github.com/magdielcardoso/active_act/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magdielcardoso%2Factive_act/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30642996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-18T01:41:58.583Z","status":"online","status_checked_at":"2026-03-18T02:00:07.824Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["open-source","rails","ruby","ruby-gem","ruby-on-rails","rubygem"],"created_at":"2025-06-20T10:01:40.569Z","updated_at":"2026-03-18T02:35:28.289Z","avatar_url":"https://github.com/magdielcardoso.png","language":"Ruby","funding_links":["https://github.com/sponsors/magdielcardoso"],"categories":["Ruby"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\".github/images/icon.svg\" alt=\"ActiveAct Logo\" width=\"350\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://badge.fury.io/rb/active_act\"\u003e\u003cimg src=\"https://badge.fury.io/rb/active_act.svg\" alt=\"Gem Version\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/magdielcardoso/active_act/actions/workflows/main.yml\"\u003e\u003cimg src=\"https://github.com/magdielcardoso/active_act/actions/workflows/main.yml/badge.svg\" alt=\"Build Status\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License: MIT\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# ActiveAct\n\nActiveAct is a Rails Engine that introduces a standardized Action layer for your Rails applications. It provides a base class and generators to help you organize business logic in a clean, reusable way.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_act'\n```\n\nAnd then execute:\n\n```sh\n$ bundle install\n```\n\nRun the install generator to set up the actions directory:\n\n```sh\n$ rails generate active_act:install\n```\n\nThis will create the `app/actions` directory. The base class `ActiveAct::ApplicationAction` is provided by the gem and does not need to be generated in your app.\n\n## Usage\n\n### Creating a new Action\n\nCreate a new action by inheriting from `ActiveAct::ApplicationAction`:\n\n```ruby\n# app/actions/send_welcome_email.rb\nclass SendWelcomeEmail \u003c ActiveAct::ApplicationAction\n  def initialize(user)\n    @user = user\n  end\n\n  def call\n    # Your business logic here\n    UserMailer.welcome(@user).deliver_later\n  rescue =\u003e e\n    fail(e)\n  end\nend\n```\n\n### Executing an Action\n\nYou can call your action from anywhere in your app:\n\n```ruby\nSendWelcomeEmail.call(user)\n```\n\n### Generating an Action with the Generator\n\nYou can use the built-in generator to quickly scaffold a new action:\n\n```sh\nrails generate active_act:action ActionName\n```\n\n**Example:**\n\n```sh\nrails generate active_act:action SendWelcomeEmail\n```\n\nThis will create the file `app/actions/send_welcome_email.rb` with the following content:\n\n```ruby\nclass SendWelcomeEmail \u003c ActiveAct::ApplicationAction\n  # Uncomment and customize the initializer if needed\n  # def initialize(args)\n  #   @args = args\n  # end\n\n  def call\n    # Implement your business logic here\n    raise NotImplementedError, \"You must implement the #call method in SendWelcomeEmail\"\n  end\nend\n```\n\n## Base Action API\n\nThe provided `ActiveAct::ApplicationAction` includes:\n\n- `.call(*args, **kwargs, \u0026block)`: Instantiates and runs the action.\n- `#call`: To be implemented in your subclass.\n- `#fail(error = nil)`: Raises an error to signal failure.\n\n## Flexible Arguments and Chaining Actions\n\n### Passing Arguments to Actions\n\nYou can define your action's `call` method to accept any arguments you need (positional or keyword). For maximum flexibility, use `*args, **kwargs`:\n\n```ruby\nclass OrderProcess \u003c ActiveAct::ApplicationAction\n  def call(order, user:)\n    # business logic here\n    { order: order, user: user }\n  end\nend\n\nOrderProcess.call(order, user: user)\n```\n\n### ActionResult: Handling Results\n\nEvery call to an action returns an `ActionResult` object, which provides:\n\n- `.value` → the value returned by your action (usually a hash or object)\n- `.error` → nil if successful, or the exception if an error occurred\n- `.success?` → true if no error\n\nExample:\n\n```ruby\nresult = OrderProcess.call(order, user: user)\nif result.success?\n  puts result.value # =\u003e { order: ..., user: ... }\nelse\n  puts \"Error: #{result.error}\"\nend\n```\n\n### Chaining Actions with `.then`\n\nYou can chain actions so that the result of one is passed as the argument to the next:\n\n```ruby\nclass NotifyUser \u003c ActiveAct::ApplicationAction\n  def call(result)\n    user = result[:user]\n    # notify user logic\n    { notified: true }\n  end\nend\n\nresult = OrderProcess.call(order, user: user).then(NotifyUser)\nif result.success?\n  puts \"User notified!\"\nelse\n  puts \"Error: #{result.error}\"\nend\n```\n\n- The value returned by the first action is passed as the first argument to the next action's `call` method.\n- You can chain as many actions as you want: `ActionA.call(...).then(ActionB).then(ActionC)`\n\n## Example\n\n```ruby\n# app/actions/process_payment.rb\nclass ProcessPayment \u003c ActiveAct::ApplicationAction\n  def initialize(order)\n    @order = order\n  end\n\n  def call\n    PaymentService.charge(@order)\n  rescue PaymentService::Error =\u003e e\n    fail(e)\n  end\nend\n\n# Usage:\nProcessPayment.call(order)\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/magdielcardoso/active_act.\n\n## How to contribute\n\n1. Fork the repository: https://github.com/magdielcardoso/active_act\n2. Create a new branch for your feature or fix:\n   ```sh\n   git checkout -b my-feature\n   ```\n3. Make your changes, including tests if applicable.\n4. Run the test suite to ensure everything is working:\n   ```sh\n   bundle install\n   bundle exec rake spec\n   ```\n5. Commit your changes and push your branch:\n   ```sh\n   git add .\n   git commit -m \"Describe your change\"\n   git push origin my-feature\n   ```\n6. Open a Pull Request on GitHub and describe your contribution.\n\nThank you for helping to improve ActiveAct!\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagdielcardoso%2Factive_act","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagdielcardoso%2Factive_act","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagdielcardoso%2Factive_act/lists"}