{"id":21800873,"url":"https://github.com/anjlab/triggerable","last_synced_at":"2025-10-08T19:07:02.663Z","repository":{"id":21007771,"uuid":"24298420","full_name":"anjlab/triggerable","owner":"anjlab","description":"Trigger/automation engine for ActiveRecord models","archived":false,"fork":false,"pushed_at":"2018-04-13T09:38:23.000Z","size":72,"stargazers_count":17,"open_issues_count":1,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-09-29T13:16:18.355Z","etag":null,"topics":["rails","ruby","schedule"],"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/anjlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-21T17:50:15.000Z","updated_at":"2023-07-21T23:35:00.000Z","dependencies_parsed_at":"2022-08-05T11:00:40.948Z","dependency_job_id":null,"html_url":"https://github.com/anjlab/triggerable","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/anjlab/triggerable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjlab%2Ftriggerable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjlab%2Ftriggerable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjlab%2Ftriggerable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjlab%2Ftriggerable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anjlab","download_url":"https://codeload.github.com/anjlab/triggerable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjlab%2Ftriggerable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000702,"owners_count":26082805,"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-10-08T02:00:06.501Z","response_time":56,"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":["rails","ruby","schedule"],"created_at":"2024-11-27T11:14:45.070Z","updated_at":"2025-10-08T19:07:02.615Z","avatar_url":"https://github.com/anjlab.png","language":"Ruby","readme":"# Triggerable\n\n[![Code Climate](https://codeclimate.com/github/anjlab/triggerable/badges/gpa.svg)](https://codeclimate.com/github/anjlab/triggerable)\n\nTriggerable is a powerful engine for adding a conditional behaviour for ActiveRecord models. This logic can be defined in two ways - as triggers and automations. Triggers are called right after model creating, updating or saving, and automations are run on schedule (e.g. 2 hours after update).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'triggerable'\n```\n\nAnd then execute:\n\n```shell\nbundle\n```\n\n## Usage\n\nSetup and defining trigger and automation:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  trigger on: :after_create, if: { receives_sms: true } do\n    user.send_welcome_sms\n  end\n\n  automation if: { created_at: { after: 24.hours }, confirmed: false } do\n    send_confirmation_email\n  end\nend\n```\n\nCombining different conditions and predicates:\n\n```ruby\ntrigger on: :after_create, if: { field: { is: 1 } }, ...\n# short form\ntrigger on: :after_create, if: { field: 1 }, ...\n\ntrigger on: :after_create, if: { field: { is_not: 1 } }, ...\n\ntrigger on: :after_create, if: { field: { in: [1, 2, 3] } }, ...\n# short form\ntrigger on: :after_create, if: { field: [1, 2, 3] }, ...\n\ntrigger on: :after_create, if: { field: { greater_than: 1 } }, ...\ntrigger on: :after_create, if: { field: { less_than: 1 } }, ...\n\ntrigger on: :after_create, if: { field: { exists: true } }, ...\n\ntrigger on: :after_create, if: { and: [{ field1: '1' }, { field2: 1 }] }, ...\ntrigger on: :after_create, if: { or: [{ field1: '1' }, { field2: 1 }] }, ...\n```\n\nTriggerable does not run automations by itself, you should call `Triggerable::Engine.run_automations(interval)` using any scheduling script. Interval is a time difference between calling the method (e.g. `1.hour`). *You should avoid situations when your interval is less then the time your automations need to complete!*\n\nAutomation calls action block for each found object, but it's possible to pass a relation to action block using `pass_relation` option: \n\n```ruby\nclass User \u003c ActiveRecord::Base\n  automation if: {\n    created_at: { after: 24.hours }, confirmed: false\n  }, pass_relation: true do\n    each(\u0026:send_confirmation_email)\n  end\nend\n```\n\nIf you have more complex condition or need to check associations (not supported in DSL now), you should use a lambda condition form:\n\n```ruby\ntrigger on: :after_update, if: -\u003e { orders.any? } do\n  # ...\nend\n```\n\nIf you need to share logic between triggers/automations bodies you can move it into separate class. It should be inherited from `Triggerable::Actions::Action` and implement a single method `run_for!(object, rule_name)` where trigger_name is a string passed to rule in :name option and obj is a triggered object. Then you can pass a name of your action class instead of do block.\n\n```ruby\nclass SendWelcomeSms \u003c Triggerable::Actions::Action\n  def run_for! object, trigger_name\n    SmsGateway.send_to object.phone, welcome_text\n  end\nend\n\nclass User\n  trigger on: :after_create, if: { receives_sms: true }, do: :send_welcome_sms\nend\n```\n\n## Logging and debugging\n\nYou can easily turn on logging and debugging (using `puts`):\n\n```ruby\nTriggerable::Engine.logger = Logger.new(File.join(Rails.root, 'log', 'triggers.log'))\nTriggerable::Engine.debug = true\n```\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanjlab%2Ftriggerable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanjlab%2Ftriggerable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanjlab%2Ftriggerable/lists"}