{"id":15288798,"url":"https://github.com/shebang-labs/acts_as_lockable_by","last_synced_at":"2026-05-09T07:05:02.124Z","repository":{"id":40231500,"uuid":"156211246","full_name":"shebang-labs/acts_as_lockable_by","owner":"shebang-labs","description":"A ruby gem to lock resources to prevent concurrent/multiple lockers access/editing of the resource at the same time","archived":false,"fork":false,"pushed_at":"2024-03-19T00:27:01.000Z","size":154,"stargazers_count":3,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T17:47:21.862Z","etag":null,"topics":["concurrency","redis","resource-locker","ruby","ruby-gem","ruby-on-rails","semaphores"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/acts_as_lockable_by","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/shebang-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2018-11-05T12:01:35.000Z","updated_at":"2023-07-21T12:48:52.000Z","dependencies_parsed_at":"2024-11-15T05:42:11.766Z","dependency_job_id":null,"html_url":"https://github.com/shebang-labs/acts_as_lockable_by","commit_stats":{"total_commits":90,"total_committers":5,"mean_commits":18.0,"dds":0.5,"last_synced_commit":"76785cb75d2d1b38fec02df3a9cf1fb2fe74334a"},"previous_names":["tareksamni/acts_as_lockable_by"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/shebang-labs/acts_as_lockable_by","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shebang-labs%2Facts_as_lockable_by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shebang-labs%2Facts_as_lockable_by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shebang-labs%2Facts_as_lockable_by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shebang-labs%2Facts_as_lockable_by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shebang-labs","download_url":"https://codeload.github.com/shebang-labs/acts_as_lockable_by/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shebang-labs%2Facts_as_lockable_by/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32533358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T11:28:32.350Z","status":"ssl_error","status_checked_at":"2026-05-02T11:27:30.140Z","response_time":132,"last_error":"SSL_read: 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":["concurrency","redis","resource-locker","ruby","ruby-gem","ruby-on-rails","semaphores"],"created_at":"2024-09-30T15:53:14.434Z","updated_at":"2026-05-09T07:05:02.089Z","avatar_url":"https://github.com/shebang-labs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActsAsLockableBy\n\n[![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb\u0026type=6\u0026v=0.1.12\u0026x2=0)](http://badge.fury.io/rb/acts_as_lockable_by)\n[![Build Status](https://travis-ci.com/shebang-labs/acts_as_lockable_by.svg?branch=master)](https://travis-ci.com/shebang-labs/acts_as_lockable_by)\n\nThis gem was originally developed, incubated and maintained at [ABTION](https://www.abtion.com/). Its main goal is providing the ability to lock a resource so that no other users/lockers can access it till the lock is released or the ttl expires. It uses `redis` a shared memory space to share locks across different deployments which enables easy horizontal scalability for your ruby/rails project on multiple servers.\n\nAn example usage for this gem is when you need a blog post (resource) to be only edtiable by 1 user concurrently. So the first user to lock the blog post to himself will always have access and be able to edit it. This user will need to renew the lock before the `ttl` expires otherwise the post will be unlocked/released and any other users can lock it to themselves.\n\n`ActsAsLockableBy` uses `redis` as a shared distributed efficient lock manager with its built-in ability to expire locks when `ttl` expires.\n\nThe `lock`, `unlock` and `renew_lock` methods in this gem are all atomic operations and running as one redis call on the redis server. Even multiple clients calling any of these methods against the same key/resource will never enter into a race condition or thread unsafety scenarios.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Installation](#installation)\n  - [Post Installation](#post-installation)\n- [Usage](#usage)\n- [Development](#development)\n- [Contributing](#contributing)\n- [License](#license)\n- [Code of Conduct](#code-of-conduct)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'acts_as_lockable_by'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install acts_as_lockable_by\n\n### Post Installation\n\nYou need to configure the gem as follows:\n\n```ruby\n# config/initializers/acts_as_lockable_by.rb\nActsAsLockableBy.configure do |config|\n  config.redis = Redis.new(url: ENV['REDIS_URL']) # redis client\n  config.ttl = 30.seconds # global ttl\nend\n```\n\n## Usage\n\nSetup\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  # :id is a unique identifier(attribute/method) for this object\n  # :ttl default to global configured ttl if not provided\n  acts_as_lockable_by :id, ttl: 60.seconds\nend\n# or if not using ActiveRecord\nclass Post\n  include ActsAsLockableBy::Lockable\n  acts_as_lockable_by :post_id # default to global configured ttl\n\n  def post_id\n    \"SOME UNIQUE IDENTIFIER\"\n  end\nend\n\npost = Post.new\n```\n\nLock and unlock a post\n\n```ruby\npost.lock('Tarek Elsamni') # true\npost.lock('Tarek Elsamni') # false - already locked!\npost.unlock('Someone Else') # false - 'Someone Else' did not lock it!\npost.unlock('Tarek Elsamni') # true - 'Tarek Elsamni' locked it!\npost.unlock('Tarek Elsamni') # false - It is already unlocked!\npost.lock!('Tarek Elsamni') # true\npost.lock!('Tarek Elsamni') # will raise LockError - already locked!\npost.unlock!('Tarek Elsamni') # true - 'Tarek Elsamni' locked it!\npost.unlock!('Tarek Elsamni') # will raise UnLockError - not locked!\n```\n\nCheck if an object/resource is locked\n\n```ruby\npost.locked? # false\npost.lock('Tarek Elsamni') # true\npost.locked? # true\n```\n\nRenew a lock before its ttl expires\n\n```ruby\npost.lock('Tarek Elsamni') # true\npost.renew_lock('Someone Else') # false - 'Someone Else' did not lock it!\npost.renew_lock('Tarek Elsamni') # true - 'Tarek Elsamni' locked it!\n```\n\nWho locked an object?\n\n```ruby\npost.lock('Tarek Elsamni') # true\npost.locked? # true\npost.locked_by_id # 'Tarek Elsamni'\n```\n\nIs a class lockable?\n\n```ruby\nPost.lockable? # true - an alias to Post.is_lockable?\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 open a PR with your changes against the main gem repo. If your code is passing current tests and highly covered by new tests then one of the maintainers will review it and merge. Auto releasing to a new gem version to `rubygems` is automated with [travis](http://travis-ci.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/shebang-labs/acts_as_lockable_by. 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## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ActsAsLockable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/shebang-labs/acts_as_lockable_by/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshebang-labs%2Facts_as_lockable_by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshebang-labs%2Facts_as_lockable_by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshebang-labs%2Facts_as_lockable_by/lists"}