{"id":18732340,"url":"https://github.com/factorialco/captain_hook","last_synced_at":"2026-02-04T12:33:00.498Z","repository":{"id":258977534,"uuid":"863024532","full_name":"factorialco/captain_hook","owner":"factorialco","description":"🪝 Create decorator hooks for any ruby class","archived":false,"fork":false,"pushed_at":"2025-09-12T08:04:49.000Z","size":77,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-12T10:11:45.186Z","etag":null,"topics":["hooks","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/factorialco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2024-09-25T15:28:58.000Z","updated_at":"2025-09-12T08:04:52.000Z","dependencies_parsed_at":"2025-04-12T18:31:31.400Z","dependency_job_id":"8d95d8c6-ac74-4d75-bf5e-b214fc220f7c","html_url":"https://github.com/factorialco/captain_hook","commit_stats":null,"previous_names":["factorialco/captain_hook"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/factorialco/captain_hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorialco%2Fcaptain_hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorialco%2Fcaptain_hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorialco%2Fcaptain_hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorialco%2Fcaptain_hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/factorialco","download_url":"https://codeload.github.com/factorialco/captain_hook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/factorialco%2Fcaptain_hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29084360,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"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":["hooks","ruby","ruby-gem"],"created_at":"2024-11-07T15:05:29.535Z","updated_at":"2026-02-04T12:33:00.478Z","avatar_url":"https://github.com/factorialco.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# captain_hook\n\nA ruby gem to decorate your methods and run arbitrary hooks `before`, `after`\nor `around` them. It is similar on how Rails does with `before_action`,\n`after_action` and `around_action` but this for any class.\n\nIt automatically wraps the configured methods to call the hooks `before`,\n`after` or `around` them.\n\n## Installation\n\nAdd the following line to your Gemfile:\n\n```ruby\ngem 'captain_hook', git: 'https://github.com/factorialco/captain_hook.git', branch: 'main'\n```\n\nThen `bundle install`\n\n## Using it\n\nIn order to inject the hook behavior, you need to include the `CaptainHook`\nmodule in your class and use the `hook` method to decorate the methods you want\nto hook.\n\n### Registering the hooks\n\n```ruby\nclass MyService\n  include CaptainHook\n\n  hook :before, methods: [:cook], hook: CookHook.new, inject: [:policy_context]\n  hook :before, methods: [:deliver], hook: ErroringHook.new\n  hook :before,\n       hook: BeforeAllHook.new,\n       exclude: [:serve],\n       skip_when: -\u003e(_args, kwargs) { !kwargs[:dto] }\n\n  hook :after, methods: [:prepare], hook: PrepareHook.new\n  hook :after, methods: [:invented_one], hook: PrepareHook.new\n\n  hook :around,\n       methods: %i[serve foo],\n       hook: ServeHook.new,\n       skip_when: -\u003e(_args, kwargs) { kwargs[:dto] }\n\n  def prepare(dto:); end\n\n  def cook; end\n\n  def serve; end\n\n  def deliver; end\nend\n```\n\nParameters:\n\n- `methods`: an array of method names to hook. If not specified, it will hook\n  all methods.\n- `hook`: the instance of the hook to run.\n- inject: The hook will receive these additional keyword arguments from the\n  class hosting the method.\n- `exclude`: an array of method names to exclude from being hooked.\n- skip_when: a lambda that receives the positional and keyword arguments of the\n  method being decorated and returns a boolean to skip the hook.\n\n### Implementing your hooks\n\nYou need to implement a class with the `#call` method.\nThis method will receive the following positional parameters:\n\n- klass: the class where the method is defined\n- method: the method name\n- block: the original method (useful for around hooks)\n\nAdditionally it will receive the positional and keyword arguments of the\noriginal method being decorated.\n\nYou can inject additional keyword parameters by using the `inject` parameter\nwhen registering the hook.\n\n### Caveats\n\n- You can not call super from a child class decorated method, you will enter in\nan infinite loop\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffactorialco%2Fcaptain_hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffactorialco%2Fcaptain_hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffactorialco%2Fcaptain_hook/lists"}