{"id":17942584,"url":"https://github.com/ngelx/resource_quotable","last_synced_at":"2026-05-14T22:41:57.081Z","repository":{"id":146964883,"uuid":"540804984","full_name":"ngelx/resource_quotable","owner":"ngelx","description":"A Rails quota limit engine for resources.","archived":false,"fork":false,"pushed_at":"2023-06-27T04:37:10.000Z","size":14172,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T20:38:04.497Z","etag":null,"topics":["rails","ruby","ruby-on-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/ngelx.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":"2022-09-24T11:22:47.000Z","updated_at":"2023-06-25T12:50:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3a0475f-8c80-4f2a-adba-8d61f3f6503c","html_url":"https://github.com/ngelx/resource_quotable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngelx%2Fresource_quotable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngelx%2Fresource_quotable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngelx%2Fresource_quotable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngelx%2Fresource_quotable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngelx","download_url":"https://codeload.github.com/ngelx/resource_quotable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247008743,"owners_count":20868419,"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":["rails","ruby","ruby-on-rails"],"created_at":"2024-10-29T03:06:21.875Z","updated_at":"2026-05-14T22:41:57.075Z","avatar_url":"https://github.com/ngelx.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ResourceQuotable\nA Rails quota limit gem for resources. UNDER DEVELOPMENT\n\n[![Gem Version](https://badge.fury.io/rb/resource_quotable.svg)](https://badge.fury.io/rb/resource_quotable)\n![Rspec suit](https://github.com/ngelx/resource_quotable/actions/workflows/release.yml/badge.svg)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/39eaf50966ab71353f66/test_coverage)](https://codeclimate.com/github/ngelx/resource_quotable/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/39eaf50966ab71353f66/maintainability)](https://codeclimate.com/github/ngelx/resource_quotable/maintainability)\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'resource_quotable'\n```\n\nAnd then execute:\n```bash\n$ bundle install\n```\n\nInstall migrations:\n```bash\n$ rails resource_quotable:install:migrations\n$ rails db:migrate\n```\n\nMount engine:\n```ruby\n# config/routes.rb\nRails.application.routes.draw do\n  # ...\n  mount ResourceQuotable::Engine =\u003e '/resource_quotable'\n  # ...\nend\n\n```\n\nConfigure:\n```ruby\n# config/initializers/resource_quotable.rb\n\nResourceQuotable.setup do |config|\n\n  ##\n  # Mandatory settings\n  #\n  # Resources to track quota.\n  #   format: Array of strings. Could be anything.\n  #\n  config.resources = %w[ResourceA ResourceB NotModel]\n\n  ##\n  # Optional settings\n\n  # Method to access group form user instance.\n  # default: 'group'\n  config.group_method = 'user_group'\n\n  # Method to access users form group instance.\n  # default: 'users'\n  config.users_method = 'admin_users'\n\n  # main_content ID for rendering.\n  # default: 'resource_quotable_content'\n  config.main_content = 'resource_quotable_content'\n\n  # Base controller.\n  # default: '::ApplicationController'\n  config.base_controller = '::ApplicationController'\n\n  # Actions\n  # Default [:create,:update, :destroy]\n  config.actions = {\n    create: 0,\n    update: 1,\n    destroy: 2,\n    send: 3\n  }.freeze\n\nend\n```\n\nAttach Quotable to model.\n\n```ruby\nclass User \u003c ApplicationRecord\n  acts_as_quota_trackable\n  # ....\n  belongs_to :group\n  # ....\nend\n\nclass Group \u003c ApplicationRecord\n  acts_as_quotable\n  # ....\n  has_many :users, dependent: :destroy\n  # ....\nend\n```\n\n## Usage\n\n```erb\n\u003c% if allowed_to? :create, 'Post' %\u003e\n  \u003c%= link_to \"New\", new_post_path %\u003e\n\u003c% end %\u003e\n```\n\n```ruby\nclass PostController \u003c ApplicationController\n  # ...\n\n  def new\n    quota_authorize! :create, 'Post'\n    # ...\n  end\n\n  def create\n    quota_increment! :create, 'Post'\n    # ...\n  end\n\n  # ...\nend\n```\n\n## Customizations\n\nCustomize views\n\n`rails g resource_quotable:views`\n\nCustomize Controllers\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  # ...\n\n  # Customize how to get the current user model to track\n  # default: current_user\n  def load_quotable_tracker_user\n    # ...\n  end\n\n  # Customize how to retrieve the group model\n  # default: quotum_params[:group_type].constantize.find(quotum_params[:group_id])\n  def load_quotable_group\n    # ...\n  end\n\n  # Customize if the current_user can access to the quota management interface\n  # default: true\n  def allowed_to_manage_quota?\n    # ...\n  end\n\n  # Customize How Quotum model are retrieve/filter. Useful for scopes\n  # default: Quotum\n  def quota_scoped\n    # ...\n  end\n\n  # hook before every action\n  # default: nil\n  def resource_quotable_before\n    # ...\n  end\n\n  # hook after every action\n  # default: nil\n  def resource_quotable_after\n    # ...\n  end\n\n  # ...\nend\n```\n\n## API\n\nStill Working on this doc....\n\nAPI is exposed as a services layer.\n\n```ruby\n\n# Check quota for 20 actions on resource for this user\nResourceQuotable::ActionServices::CheckMultiple.call(user: user, resource: 'ResourceX', action: :create, amount: 20)\n# Increment 20 quota for actions on resource for this user\nResourceQuotable::ActionServices::IncrementMultiple.call(user: user, resource: 'ResourceX', action: :create, amount: 20)\n\n# Reset. Probably a good idea to have a cron job that call this.\nResourceQuotable::Reset::Any.call\nResourceQuotable::Reset::Yearly.call\nResourceQuotable::Reset::Monthly.call\nResourceQuotable::Reset::Weekly.call\nResourceQuotable::Reset::Daily.call\n```\n\n## Contributing\n\nDevelopment environment is available in a devcontainer. You can use it to develop the gem.\n\n```bash\n$ docker compose -f .devcontainer/compose.yaml build\n$ docker compose -f .devcontainer/compose.yaml run --rm rails-app bundle install\n$ docker compose -f .devcontainer/compose.yaml run --rm rails-app bundle rails db:setup\n$ docker compose -f .devcontainer/compose.yaml run --rm rails-app bundle rspec\n```\n\nThe project follows conventional commit messages. See [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for more details.\n\n```bash\n$ git commit -m \"feat: add new feature\"\n$ git commit -m \"fix: fix bug\"\n$ git commit -m \"refactor: refactor code\"\n$ git commit -m \"test: add tests\"\n$ git commit -m \"docs: add documentation\"\n$ git commit -m \"chore: other changes\"\n```\n\nVersion are automatically bumped by the release workflow. See [Release Please](https://github.com/googleapis/release-please) for more details.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngelx%2Fresource_quotable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngelx%2Fresource_quotable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngelx%2Fresource_quotable/lists"}