{"id":15064585,"url":"https://github.com/yasaichi/everett","last_synced_at":"2025-04-10T12:23:04.740Z","repository":{"id":46541975,"uuid":"76110051","full_name":"yasaichi/everett","owner":"yasaichi","description":":eyes: Substitute for Active Record Observer on Rails 5","archived":false,"fork":false,"pushed_at":"2023-12-15T20:22:48.000Z","size":67,"stargazers_count":22,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:11:18.975Z","etag":null,"topics":["observer","rails"],"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/yasaichi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"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":"2016-12-10T12:03:50.000Z","updated_at":"2023-07-19T01:39:24.000Z","dependencies_parsed_at":"2024-09-25T03:26:27.172Z","dependency_job_id":"ae514e33-4cde-4e67-8f40-06c84df8dceb","html_url":"https://github.com/yasaichi/everett","commit_stats":{"total_commits":58,"total_committers":1,"mean_commits":58.0,"dds":0.0,"last_synced_commit":"b88e651b3e0b026c8468b3f5b793dff8fbe72401"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasaichi%2Feverett","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasaichi%2Feverett/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasaichi%2Feverett/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasaichi%2Feverett/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yasaichi","download_url":"https://codeload.github.com/yasaichi/everett/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980831,"owners_count":21027803,"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","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":["observer","rails"],"created_at":"2024-09-25T00:21:23.651Z","updated_at":"2025-04-10T12:23:04.719Z","avatar_url":"https://github.com/yasaichi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Everett\n\n[![Gem Version](https://badge.fury.io/rb/everett.svg)](http://badge.fury.io/rb/everett)\n[![Build Status](https://travis-ci.org/yasaichi/everett.svg?branch=master)](https://travis-ci.org/yasaichi/everett)\n[![Code Climate](https://codeclimate.com/github/yasaichi/everett/badges/gpa.svg)](https://codeclimate.com/github/yasaichi/everett)\n[![Test Coverage](https://codeclimate.com/github/yasaichi/everett/badges/coverage.svg)](https://codeclimate.com/github/yasaichi/everett/coverage)\n\nEverett is a substitute for Active Record Observer on Rails 5.\n\n## Installation\n\nPut this in your Gemfile:\n\n```ruby\ngem 'everett'\n```\n\nRun the installation generator with:\n\n```sh\n$ rails g everett:install\n```\n\nThey will install the initializer into `config/initializers/everett.rb`.\n\n## Usage\n\n### Overview\n\nObservers allow you to implement trigger-like behavior outside the original classes.  \nYou can put them anywhere, for example `app/models/contact_observer.rb`:\n\n```ruby\nclass ContactObserver \u003c Everett::Observer\n  def after_create(contact)\n    Rails.logger.info('New contact has been added!')\n  end\n\n  def after_destroy(contact)\n    Rails.logger.info(\"Contact with an id of #{contact.id} has been destroyed!\")\n  end\nend\n```\n\nThis observer prints a log message when specific callbacks are triggered.\n\nJust like Active Record Observer, the convention is to name observers after the class they observe.  \nIf you need to change this, or want to use one observer for several classes, use `observe`:\n\n```ruby\nclass NotificationsObserver \u003c Everett::Observer\n  observe :comment, :like\n\n  def after_create(record)\n    # notifiy users of new comment or like\n  end\nend\n```\n\nNote that you must register observers first to activate them.  \nThis can be done by adding the following line into `config/initializers/everett.rb`:\n\n```ruby\nconfig.observers = :contact_observer, :notifications_observer\n```\n\n### after\\_{create,update,destroy}\\_commit\n\nSince `after_create_commit`, `after_update_commit` and `after_destroy_commit` were introduced in Rails 5,\nyou can also use them in observers:\n\n```ruby\nclass CommentObserver \u003c Everett::Observer\n  def after_create_commit(comment)\n    CommentMailer.notification(comment).deliver_now\n  end\nend\n```\n\nThis observer sends an email after a record has been created.\n\n## Migration from rails-observers\n\nSince Everett is highly compatible with Active Record Observer,\nyou can easily migrate from [rails-observers](https://github.com/rails/rails-observers).  \nAll you need to do is as follows:\n\n### 1. Replace ActiveRecord::Observer with Everett::Observer\n\n```diff\n-class ContactObserver \u003c ActiveRecord::Observer\n+class ContactObserver \u003c Everett::Observer\n```\n\n### 2. Register observers in config/initializers/everett.rb\n\n```diff\n# config/application.rb\n-config.active_record.observers = :contact_observer, :notifications_observer\n\n# config/initializers/everett.rb\n+Everett.configure do |config|\n+  config.observers = :contact_observer, :notifications_observer\n+end\n```\n\n### 3. Check the test suite passes\n\nIf you find any bugs, please document them on [the issues page](https://github.com/yasaichi/everett/issues).\n\n## Contributing\n\nYou should follow the steps below.\n\n1. [Fork the repository](https://help.github.com/articles/fork-a-repo/)\n2. Create a feature branch: `git checkout -b add-new-feature`\n3. Commit your changes: `git commit -am 'Add new feature'`\n4. Push the branch: `git push origin add-new-feature`\n5. [Send us a pull request](https://help.github.com/articles/about-pull-requests/)\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasaichi%2Feverett","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyasaichi%2Feverett","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasaichi%2Feverett/lists"}