{"id":18513349,"url":"https://github.com/jbox-web/royce","last_synced_at":"2025-04-09T06:33:12.563Z","repository":{"id":62960956,"uuid":"169008203","full_name":"jbox-web/royce","owner":"jbox-web","description":" A Ruby on Rails roles solution","archived":false,"fork":false,"pushed_at":"2024-09-06T16:07:43.000Z","size":153,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-06T19:15:29.870Z","etag":null,"topics":["rails","roles-management","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/jbox-web.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"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":"2019-02-04T00:09:29.000Z","updated_at":"2024-09-06T16:07:47.000Z","dependencies_parsed_at":"2024-08-11T05:27:59.741Z","dependency_job_id":"0c8defe2-f272-40fa-93ad-67f2a37f7540","html_url":"https://github.com/jbox-web/royce","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Froyce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Froyce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Froyce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Froyce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/royce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223367283,"owners_count":17134070,"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","roles-management","ruby"],"created_at":"2024-11-06T15:37:46.732Z","updated_at":"2024-11-06T15:37:47.888Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Royce\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/royce.svg)](https://github.com/jbox-web/royce/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/jbox-web/royce.svg)](https://github.com/jbox-web/royce/releases/latest)\n[![CI](https://github.com/jbox-web/royce/workflows/CI/badge.svg)](https://github.com/jbox-web/royce/actions)\n[![Code Climate](https://codeclimate.com/github/jbox-web/royce/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/royce)\n[![Test Coverage](https://codeclimate.com/github/jbox-web/royce/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/royce/coverage)\n\nRoles in Rails.\n\n## Installation\n\nPut this in your `Gemfile` :\n\n```ruby\ngit_source(:github){ |repo_name| \"https://github.com/#{repo_name}.git\" }\n\ngem 'royce', github: 'jbox-web/royce', tag: '1.3.0'\n```\n\nthen run `bundle install`.\n\nRun this in your terminal to generate DB migration :\n\n```sh\nbin/rails g royce:install\nbin/rails db:migrate\n```\n\nAdd this to a model :\n\n```ruby\nroyce_roles %w[owner editor administrator]\n```\n\n## In Depth\n\nAdding royce to a model is super simple. The following code will add the roles `user`, `admin`, and `editor` to your model class.\nYou can pass in an array of strings or symbols. You can even pass in a mixed array of strings and symbols.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  royce_roles %w[user admin editor] # array of strings\nend\n\nclass Sailor \u003c ActiveRecord::Base\n  royce_roles %i[captain bosun quartermaster] # array of symbols\nend\n\nclass RockAndRoller \u003c ActiveRecord::Base\n  royce_roles [:drummer, 'bassist', :editor] # array of strings and symbols\nend\n```\n\nNow instances of your user class have some roles methods. You can add, remove, query role status, and even ask if an instance can accept such a role.\n\n```ruby\nuser = User.create()\n\nuser.add_role :user\nuser.add_role 'user'\nuser.add_role Royce::Role.find_by(name: 'user')\n\nuser.remove_role :user\nuser.remove_role 'user'\nuser.remove_role Royce::Role.find_by(name: 'user')\n\nuser.has_role? :user\nuser.has_role? 'user'\nuser.has_role? Royce::Role.find_by(name: 'user')\n\nuser.allowed_role? 'user'\nuser.allowed_role? :user\nuser.allowed_role? Royce::Role.find_by(name: 'user')\n```\n\nYou also get some conveneint methods to query if a user has a certain named role.\n\n```ruby\nuser.admin?\nuser.editor?\nuser.user?\n```\n\nYou can easily add a role to your model object using our bang! methods.\n\n```ruby\nuser.user!\nuser.admin!\nuser.editor!\n```\n\nGet a list of roles that a particular user has\n\n```ruby\nuser.add_role :user\nuser.add_role :admin\nuser.role_list # =\u003e ['user', 'admin']\n```\n\nGet a list of all roles available to a class\n\n```ruby\nUser.available_role_names # =\u003e ['user', 'admin', 'editor']\n```\n\nNot enough. You also get named scopes on your models.\n\n```ruby\nUser.admins\nUser.editors\nUser.users\n```\n\nIf you liked that, you'll LOVE this. We've added the ability to take a role, and return all instances of a class that have that role.\n\nFor `User`s it'll look like this:\n\n```ruby\nadmin_role = Royce::Role.find_by(name: 'admin')\nadmin_role.users.all # Array of user objects\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Froyce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Froyce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Froyce/lists"}