{"id":31009385,"url":"https://github.com/robhurring/action_kit","last_synced_at":"2025-09-13T04:34:50.853Z","repository":{"id":36307647,"uuid":"40612263","full_name":"robhurring/action_kit","owner":"robhurring","description":"Wrappers around Interactors","archived":false,"fork":false,"pushed_at":"2015-08-12T21:37:44.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-13T19:19:37.636Z","etag":null,"topics":[],"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/robhurring.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}},"created_at":"2015-08-12T16:40:58.000Z","updated_at":"2015-08-12T16:51:26.000Z","dependencies_parsed_at":"2022-09-04T20:01:26.947Z","dependency_job_id":null,"html_url":"https://github.com/robhurring/action_kit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robhurring/action_kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robhurring%2Faction_kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robhurring%2Faction_kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robhurring%2Faction_kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robhurring%2Faction_kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robhurring","download_url":"https://codeload.github.com/robhurring/action_kit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robhurring%2Faction_kit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274919766,"owners_count":25373953,"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","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"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":[],"created_at":"2025-09-13T04:34:46.244Z","updated_at":"2025-09-13T04:34:50.845Z","avatar_url":"https://github.com/robhurring.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActionKit\n\nAction kit is a bunch of patterns I've used around the excellent [interactor](https://github.com/collectiveidea/interactor) gem. \n\nThis is currently half-baked as its just being extracted from projects. Hopefully I will find some time to make it more robust.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'action_kit', github: 'robhurring/action_kit'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install action_kit\n\n## Usage\n\n##### Basic Context Contracts\n\n`Action` provides very basic input/output contracts by checking that the context has the proper `expects` keys set, and returns the proper `promises` keys on successful runs.\n\n```ruby\n# app/actions/login_user.rb\nclass LoginUser\n  include Action\n\n  expects :username, :password\n  promises :logged_in\n\n  def call\n    if User.login(username, password)\n      context.logged_in = true\n    else\n      context.fail!\n    end\n  end\n\n  private\n\n  delegate :username, :password, to: :context\nend\n```\n\n##### Basic Caching\n\n`ActionCache` provides basic interactor result caching. \n\n* Caching defaults to using `Marshal` as its serializer to keep complex objects safe -- this can be swapped out by changing `ActionCache.serializer` to anything that implements `#dump` and `#load` (see: [ActionCache::Serializer::Marshal](lib/action_kit/serializer/marshal.rb))\n* To swap out the cache you can change `ActionCache.cache` to any object that implements `#fetch(key, options, \u0026block)` (see: [ActionCache::Cache::Worthless](lib/action_kit/cache/worthless.rb))\n\n*NOTE:* This only caches successful calls. If `context.failure?` is true then no caching will take place.\n\n**WARNING:** Merging `OpenStruct` contexts is tricky and not one-size-fits-all (at least not yet). Have a look at the [context merging strategies](lib/action_kit/merge_strategy) to see what can work. The default is [paranoid](lib/action_kit/merge_strategy/paranoid.rb) and only sets *new* keys on the context instead of overwriting anything.\n\n```ruby\n# config/initializers/action_kit\nActionKit::ActionCache.cache = Rails.cache\nActionKit::ActionCache.logger = Rails.logger\nActionKit::ActionCache.enabled = !Rails.env.test?\n\n# app/actions/get_user.rb\nclass GetUser\n  include Action\n  include ActionCache\n\n  cache_key do |context|\n    %(users:#{context.username})\n  end\n\n  expires_in 1.hour\n\n  expects :username\n  promises :user\n\n  def call\n    response = api.get(username)\n\n    if response.success?\n      context.user = response.user\n    else\n      context.fail!(error: response.error)\n    end\n  end\n\n  private\n\n  delegate :username, to: :context\n\n  def api\n    Company::API::Users\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` 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/[USERNAME]/action_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobhurring%2Faction_kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobhurring%2Faction_kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobhurring%2Faction_kit/lists"}