{"id":19474596,"url":"https://github.com/tomasc/mongoid_activity_tracker","last_synced_at":"2025-04-25T12:31:51.286Z","repository":{"id":19728827,"uuid":"22984919","full_name":"tomasc/mongoid_activity_tracker","owner":"tomasc","description":"Minimal set of classes and modules to help with activity tracking.","archived":false,"fork":false,"pushed_at":"2019-01-22T09:17:22.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T14:50:56.295Z","etag":null,"topics":[],"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/tomasc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-15T09:27:26.000Z","updated_at":"2019-02-14T11:07:57.000Z","dependencies_parsed_at":"2022-08-20T23:40:16.920Z","dependency_job_id":null,"html_url":"https://github.com/tomasc/mongoid_activity_tracker","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid_activity_tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid_activity_tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid_activity_tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid_activity_tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasc","download_url":"https://codeload.github.com/tomasc/mongoid_activity_tracker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250817790,"owners_count":21492223,"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":[],"created_at":"2024-11-10T19:25:49.310Z","updated_at":"2025-04-25T12:31:49.753Z","avatar_url":"https://github.com/tomasc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoid Activity Tracker\n\n[![Build Status](https://travis-ci.org/tomasc/mongoid_activity_tracker.svg)](https://travis-ci.org/tomasc/mongoid_activity_tracker) [![Gem Version](https://badge.fury.io/rb/mongoid_activity_tracker.svg)](http://badge.fury.io/rb/mongoid_activity_tracker) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_activity_tracker.svg)](https://coveralls.io/r/tomasc/mongoid_activity_tracker)\n\nModule to help with tracking activity in your application.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```Ruby\ngem 'mongoid_activity_tracker'\n```\n\nAnd then execute:\n\n```\n$ bundle\n```\n\nOr install it yourself as:\n\n```\n$ gem install mongoid_activity_tracker\n```\n\n## Usage\n\nSetup a class that will record the activity:\n\n```Ruby\nclass MyTracker\n  include MongoidActivityTracker::Tracker\nend\n```\n\nTrack the activity:\n\n```Ruby\nres = MyTracker.track(current_user, :create)\n\nres.actor # returns the current_user\nres.actor_cache # =\u003e { to_s: … }\nres.actor_cache_object.to_s # the 'actor_cache_object' wraps the actor_cache hash into an OpenStruct\nres.action # =\u003e :create\n```\n\n## Configuration\n\nAlong the action, it is possible to track any number of related documents.\n\nFirst, configure the tracker class using the `.tracks` macro:\n\n```Ruby\nclass MyTracker\n  include MongoidActivityTracker::Tracker\n  tracks :subject\nend\n```\n\nThen, specify the subject when tracking the activity:\n\n```Ruby\nres = MyTracker.track(current_user, :create, subject: my_subject)\n\nres.subject # =\u003e my_subject\nres.subject_cache # =\u003e { to_s: … }\nres.subject_cache_object.to_s # …\n```\n\nBy default, the `:cache_methods` parameter is set to store the result of `:to_s` method. This is valuable for example when displaying activity overview (no need for additional query for the related document), or should the related document no longer exist. The list of methods to be cached can be customised as follows:\n\n```Ruby\nclass MyTracker\n  include MongoidActivityTracker::Tracker\n  tracks :actor, cache_methods: [:to_s, :first_name, :last_name]\n  tracks :subject, cache_methods: [:to_s, :some_other_method]\nend\n```\n\nThe tracker class can be also subclassed:\n\n```Ruby\nclass MyTrackerWithTarget \u003c MyTracker\n  tracks :target\nend\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/tomasc/mongoid_activity_tracker/fork )\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 a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fmongoid_activity_tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasc%2Fmongoid_activity_tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fmongoid_activity_tracker/lists"}