{"id":13483104,"url":"https://github.com/elorest/petergate","last_synced_at":"2026-03-09T02:32:24.519Z","repository":{"id":23104395,"uuid":"26458639","full_name":"elorest/petergate","owner":"elorest","description":"Easy to use and read action and content based authorizations.","archived":false,"fork":false,"pushed_at":"2025-06-19T16:47:03.000Z","size":564,"stargazers_count":194,"open_issues_count":3,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-11-08T05:21:28.550Z","etag":null,"topics":["hacktoberfest","hacktoberfest2020"],"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/elorest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2014-11-10T22:22:14.000Z","updated_at":"2025-08-15T13:02:00.000Z","dependencies_parsed_at":"2025-08-21T05:36:09.781Z","dependency_job_id":"840d8888-f4bf-4fd2-bde5-7704b7d8bde9","html_url":"https://github.com/elorest/petergate","commit_stats":null,"previous_names":["isaacsloan/petergate"],"tags_count":59,"template":false,"template_full_name":null,"purl":"pkg:github/elorest/petergate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elorest%2Fpetergate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elorest%2Fpetergate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elorest%2Fpetergate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elorest%2Fpetergate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elorest","download_url":"https://codeload.github.com/elorest/petergate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elorest%2Fpetergate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30280859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:23:26.802Z","status":"ssl_error","status_checked_at":"2026-03-09T02:22:46.175Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["hacktoberfest","hacktoberfest2020"],"created_at":"2024-07-31T17:01:08.272Z","updated_at":"2026-03-09T02:32:24.498Z","avatar_url":"https://github.com/elorest.png","language":"Ruby","funding_links":[],"categories":["Ruby","Authorization"],"sub_categories":[],"readme":"[![Petergate](https://github.com/elorest/petergate/blob/master/dummy/public/petergate.png)](https://github.com/elorest/petergate)\n\n[![Build Status](https://travis-ci.org/elorest/petergate.svg)](https://travis-ci.org/dburnsii/petergate)\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/isaacsloan/petergate?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Gem Version](https://badge.fury.io/rb/petergate.svg)](http://badge.fury.io/rb/petergate)\n\n\n\n\u003e If you like the straight forward and effective nature of [Strong Parameters](https://github.com/rails/strong_parameters) and suspect that [cancan](https://github.com/ryanb/cancan) might be overkill for your project then you'll love [Petergate's](https://github.com/isaacsloan/petergate) easy to use and read action and content based authorizations.\"\n\u003e\n\u003e -- \u003ccite\u003e1 Peter 3:41\u003c/cite\u003e\n\nInstallation\n------\n##### Get the gem\nAdd this line to your application's Gemfile:\n\n    gem 'petergate'\n\nAnd then execute:\n\n    bundle\n\nOr install it yourself as:\n\n    gem install petergate\n\n##### Prerequisites: Setup Authentication (Devise)\n\nMake sure your user model is defined in\n    app/models/user.rb\nand called User.\n\nIf you're using [devise](https://github.com/plataformatec/devise) you're in luck, otherwise you'll have to add following methods to your project:\n\n    current_user\n    after_sign_in_path_for(current_user)\n    authenticate_user!\n\n##### Run the generators\n\n    rails g petergate:install\n    rake db:migrate\n\nThis will add a migration and insert petergate into your User model.\n\nUsage\n------\n#### User Model\n\nConfigure available roles by modifying this block at the top of your user.rb.\n\n```ruby\n############################################################################################\n## PeterGate Roles                                                                        ##\n## The :user role is added by default and shouldn't be included in this list.             ##\n## The :root_admin can access any page regardless of access settings. Use with caution!   ##\n## The multiple option can be set to true if you need users to have multiple roles.       ##\npetergate(roles: [:admin, :editor], multiple: false)                                      ##\n############################################################################################\n```\n\n##### Instance Methods\n\n```ruby\nuser.role =\u003e :editor\nuser.roles =\u003e [:editor, :user]\nuser.roles=(v) #sets roles\nuser.available_roles =\u003e [:admin, :editor]\nuser.has_roles?(:admin, :editors) # returns true if user is any of roles passed in as params.\n```\n##### Class Methods\n\n`User.#{role}_editors =\u003e #list of editors. Method is created for all roles. Roles [admin, :teacher] will have corresponding methods role_admins, role_teachers, etc.`\n\n#### Controllers\n\nSetup permissions in your controllers the same as you would for a before filter like so:\n\n```ruby\naccess all: [:show, :index], user: {except: [:destroy]}, company_admin: :all\n\n# one other option that might seem a bit weird is to put a group of roles in an array:\naccess [:all, :user] =\u003e [:show, :index]\n```\n\nInside your views you can use logged_in?(:admin, :customer, :etc) to show or hide content.\n\n```erb\n\u003c%= link_to \"destroy\", destroy_listing_path(listing) if logged_in?(:admin, :customer, :etc) %\u003e\n```\n\nIf you need to access available roles within your project you can by calling:\n\n```ruby\nUser::ROLES\n# or from an instance\nUser.first.available_roles\n# ROLES is a CONSTANT and will still work from within the User model instance methods\n# like in this default setter:\n\ndef roles=(v)\n  self[:roles] = v.map(\u0026:to_sym).to_a.select{|r| r.size \u003e 0 \u0026\u0026 ROLES.include?(r)}\nend\n```\nIf you need to deny access you can use the forbidden! method:\n\n```ruby\nbefore_action :check_active_user\n\ndef check_active_user\n  forbidden! unless current_user.active\nend\n```\nIf you want to change the `permission denied` message you can add to the access line:\n\n```ruby\naccess user: [:show, :index], message: \"You shall not pass\"\n```\n\n#### User Admin Example Form for Multiple Roles\n\n```slim\n= form_for @user do |f| \n  - if @user.errors.any? \n    #error_explanation \n      h2 = \"#{pluralize(@user.errors.count, \"error\")} prohibited this user from being saved:\" \n      ul \n        - @user.errors.full_messages.each do |message| \n          li = message \n \n  .field \n    = f.label :email \n    = f.text_field :email \n  - if @user.new_record? || params[:passwd] \n    .field \n      = f.label :password \n      = f.text_field :password \n    .field \n      = f.label :password_confirmation \n      = f.text_field :password_confirmation \n  .field \n    = f.label :roles \n    = f.select :roles, @user.available_roles, {}, {multiple: true} \n  .actions = f.submit \n```\n\n#### User Admin Example Form for Single Role Mode\n\n```slim\n= form_for @user do |f| \n  - if @user.errors.any? \n    #error_explanation \n      h2 = \"#{pluralize(@user.errors.count, \"error\")} prohibited this user from being saved:\" \n      ul \n        - @user.errors.full_messages.each do |message| \n          li = message \n \n  .field \n    = f.label :email \n    = f.text_field :email \n  - if @user.new_record? || params[:passwd] \n    .field \n      = f.label :password \n      = f.text_field :password \n    .field \n      = f.label :password_confirmation \n      = f.text_field :password_confirmation \n  .field \n    = f.label :role \n    = f.select :role, @user.available_roles\n  .actions = f.submit \n```\nCredits\n-------\n\nPeterGate is written and maintaned by Isaac Sloan and friends.\n\n\n## Contributing\n\n1. Fork it ( https://github.com/isaacsloan/petergate/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%2Felorest%2Fpetergate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felorest%2Fpetergate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felorest%2Fpetergate/lists"}