{"id":31193342,"url":"https://github.com/infinum/rails_log_book","last_synced_at":"2025-10-27T15:17:18.611Z","repository":{"id":17701408,"uuid":"82535268","full_name":"infinum/rails_log_book","owner":"infinum","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-18T09:53:55.000Z","size":339,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-09-16T12:40:46.966Z","etag":null,"topics":["ruby"],"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/infinum.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":"2017-02-20T08:39:32.000Z","updated_at":"2025-08-18T09:29:27.000Z","dependencies_parsed_at":"2022-08-07T09:00:10.858Z","dependency_job_id":null,"html_url":"https://github.com/infinum/rails_log_book","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/infinum/rails_log_book","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2Frails_log_book","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2Frails_log_book/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2Frails_log_book/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2Frails_log_book/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infinum","download_url":"https://codeload.github.com/infinum/rails_log_book/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2Frails_log_book/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276022596,"owners_count":25571825,"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-19T02:00:09.700Z","response_time":108,"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":["ruby"],"created_at":"2025-09-20T00:33:44.569Z","updated_at":"2025-09-20T00:34:08.907Z","avatar_url":"https://github.com/infinum.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LogBook\n\nLogBook is a gem that tracks changes on your records. Created for the purpuse of auditing and showing activity log.\nFor comparison with [paper_\\__trail](https://github.com/airblade/paper_trail) and [audited](https://github.com/collectiveidea/audited) see []()\n\n## Supported ORMs\n\nCurrently only supports ActiveRecord.\n\n## Instalation\n\nAdd to your Gemfile:\n\n``` ruby\ngem 'rails_log_book'\n```\n\nThen run:\n\n```ruby\nrails generate log_book:install\nrake db:migrate\n```\n## Reasoning\n\nWe built this gem because others did not offer us what we needed.\n\nBenefits:\n- new features ([Squashing](#squashing))\n- Explicit (needs to be told when to record, as opposed to paper_trail or audited which always record; ie. do not record stuff done in console)\n- Has an inbuilt caching mechanism with `meta` field\n- ``meta`` field can also be used to add aditional keys on which search queries can be run\n\n## Usage\n\nAdd to models you want to keep track of:\n\n``` ruby\n  class User \u003c ActiveRecord::Base\n    include LogBook::Recorder\n\n    has_log_book_records\n  end\n```\n\nAdd to controlers and actions you want the tracker to be active:\n\n``` ruby\n  class UsersController \u003c ApplicationController\n    include LogBook::ControllerRecord\n  end\n```\n\nBy default, whenever a user record is created, updated or deleted in any actions of users\\_controller a new log\\_book record will be created.\n\n## Squashing\n\nThe idea of squashing came when we needed to show an activity page where you have a has_many relation setup but you need to show changes only on the \"main\" object.\n\nExample:\n\n```ruby\nclass Hotel \u003c ApplicationRecord\n  include LogBook::Recorder\n  has_log_book_records\n\n  has_many :amenities\n  accepts_nested_attributes_for :amenities\nend\n\nclass HotelAmenity \u003c ApplicationRecord\n  include LogBook::Recorder\n  has_log_book_records, parent: :hotel\n\n  belongs_to :hotel\n  belongs_to :amenity\nend\n\nclass Amenity \u003c ApplicationRecord\n  has_many :hotels\nend\n\nclass HotelsController \u003c ApplicationController\n  def create\n    @hotel = Hotel.create(hotel_params)\n  end\n\n  def hotel_params\n    params.require(:hotel).permit(amenities_attributes: [:id, :status])\n  end\nend\n\n# having this params passed to hotels_controller:\n{ name: 'Hotel', amenitites_attributes: { 0: {id: 1, status: :avaliable}, 1: { id: 4, status: :unavaliable } } }\n\n# Without squashing you would have these records in the DB (abbreviated for clairity)\n[\n  {subject_type: 'Hotel',        subject_id: 1, parent_type: nil,     parent_id: nil, record_changes: { name: [nil, 'Hotel']}},\n  {subject_type: 'HotelAmenity', subject_id: 1, parent_type: 'Hotel', parent_id: 1,   record_changes: { name: [nil, 'avaliable']}},\n  {subject_type: 'HotelAmenity', subject_id: 4, parent_type: 'Hotel', parent_id: 1,   record_changes: { name: [nil, 'unavaliable']}},\n]\n\n# The above is rather difficult to paginate if you want to show changes done on HotelAmenities to show under Hotel.\n# With squashing enabled:\n[\n  {\n    subject_type: 'Hotel',\n    subject_id: 1,\n    parent_type: nil,\n    parent_id: nil,\n    record_changes: {\n      name: [nil, 'Hotel'],\n      hotel_amenitites: {\n        1: {status: [nil, 'avaliable']},\n        2: {status: [nil, 'unavaliable']}\n      }\n    }\n  }\n]\n\n```\n\n## ActiveRecord Options\n\n### fields\n\n``` ruby\n  class User \u003c ActiveRecord::Base\n    include LogBook::Recorder\n\n    # all fields\n    # has_log_book_records\n\n    # Only fields\n    # has_log_book_records only: [:email, :name]\n\n    # Ignored fields\n    # has_log_book_records except: [:password]\n\n    # Default ignored fields\n    # primary_key (id), LogBook.config.ignored_attributes (:created_at, :updated_at)\n  end\n```\n\n### callbacks\n\n``` ruby\n  class User \u003c ActiveRecord::Base\n    include LogBook::Recorder\n\n    # all events\n    # has_log_book_records\n\n    # Only record on create and destroy (not update)\n    # has_log_book_records on: [:create, :destroy]\n  end\n```\n\n### parent\n\nDefine who is a parent of this object.\n\n``` ruby\n  class User \u003c ActiveRecord::Base\n    include LogBook::Recorder\n    belongs_to :company\n\n    # Parent is Company and will be recorded with each user change\n    # has_log_book_records parent: :company\n  end\n```\n\n### parent_of\n\nDefine who this object is a parent of.\n\n``` ruby\n  class Account \u003c ActiveRecord::Base\n    include LogBook::Recorder\n    has_many :user_memberships\n    has_many :users, through: :user_memberships\n  end\n\n  def UserMembership \u003c ActiveRecord::Base\n    belongs_to :account\n    belongs_to :user\n  end\n\n  class User \u003c ActiveRecord::Base\n    has_one :user_membership\n    has_one :account, through: :user_membership\n\n    # Parent is Company and will be recorded with each user change\n    # has_log_book_records parent_of: :account\n  end\n```\n\n### meta\n\nArbitrary column. This is a jsonb field which can have all kinds of information. Useful when you want to cache fields at the exact point of record creation\n\n``` ruby\n  class User \u003c ActiveRecord::Base\n    include LogBook::Recorder\n\n    # runs `log_book_meta(record)` method to assign to `:meta` field\n    # has_log_book_records meta: true\n\n    # runs `meta_method` method to assing to `:meta` field\n    # has_log_book_records meta: :meta_method\n\n    # runs passed proc to assing to `:meta` field\n    # has_log_book_records meta: -\u003e { { slug: email.split('@').first } }\n  end\n```\n\n## ActionController options\n\n### current\\_author\n\nDefines what method is run when looking for the author for recording\n\n``` ruby\n  class Admin::UsersController \u003c ActionController::Base\n    inlcude LogBook::ControllerRecord\n\n    # defaults to `current_user`\n    def current_author\n      current_admin\n    end\n```\n\n## Configuration\n\n``` ruby\n# config/initializers/log_book.rb\nLogBook.configure do |config|\n  config.ignored_attributes = [:updated_at, :created_at]\n  config.author_method = :current_user\n  config.record_squashing = false\n  config.always_record = false\n  config.skip_if_empty_actions = [:update]\nend\n```\n\n## Additional methods\n\n``` ruby\nLogBook.with_recording {}         #=\u003e Enables recording within block\nLogBook.author=(author)           #=\u003e Records as a different author within block\nLogBook.action=(value)            #=\u003e Change default action for this request\nLogBook.with_record_squashing {}  #=\u003e Squashes records within block\nLogBook.enable_recording          #=\u003e Enables recording from this point\nLogBook.disable_recording         #=\u003e Disables recording from this point\nLogBook.record_squashing_enabled  #=\u003e Enables record squashing from this point\nLogBook.recording_enabled         #=\u003e Returns true if recording is enabled\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` 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/infinum/log_book. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://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%2Finfinum%2Frails_log_book","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfinum%2Frails_log_book","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinum%2Frails_log_book/lists"}