{"id":19681009,"url":"https://github.com/codewars/batcan","last_synced_at":"2025-10-07T19:07:42.295Z","repository":{"id":73889963,"uuid":"25956556","full_name":"codewars/batcan","owner":"codewars","description":"Heroic authorizations system for ruby. Both simple and highly flexible. ","archived":false,"fork":false,"pushed_at":"2020-10-29T20:33:59.000Z","size":15,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-10T05:36:12.684Z","etag":null,"topics":[],"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/codewars.png","metadata":{"files":{"readme":"README.md","changelog":"changes.md","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}},"created_at":"2014-10-30T05:43:22.000Z","updated_at":"2022-07-24T04:26:53.000Z","dependencies_parsed_at":"2023-09-21T12:01:27.417Z","dependency_job_id":null,"html_url":"https://github.com/codewars/batcan","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewars%2Fbatcan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewars%2Fbatcan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewars%2Fbatcan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewars%2Fbatcan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codewars","download_url":"https://codeload.github.com/codewars/batcan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240990718,"owners_count":19889929,"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":[],"created_at":"2024-11-11T18:06:43.539Z","updated_at":"2025-10-07T19:07:42.238Z","avatar_url":"https://github.com/codewars.png","language":"Ruby","readme":"# Batcan\n\n## Usage Example\n\n```ruby\n# simple example user. You can use PORO if you want.\n\nUser = Struct.new(:role) do\n  include Batcan::Canable\n\n  # the default ability if a more specific one is not defined\n  def default_can?(action, target, options = {})\n    !!role # by default if a user has any role than they are permitted\n  end\nend\n\nclass Team\n  include Batcan::Permissible\n\n  def members\n    @members ||= []\n  end\n\n  permission :join do |team, user|\n    # returning a string is like returning false (not allowed) but with a reason\n    \"guest role is not allowed to join\" if user.role == :guest\n    # if nil is returned then default_can? value will be used\n  end\n\n  permission :delete do |team, user|\n    # only admins are allowed, everyone else will be dissollowed\n    user.role == :admin\n  end\n\n  # field level permissions\n  permission :add, :members do |team, user|\n    # allow members to be added if the user is a member\n    team.members.include? user\n  end\nend\n\nuser = User.new(:admin)\nteam = Team.new\n\nuser.can?(:join, team) # returns true\nuser.role = :guest\nuser.can!(:join, team) # raises an error\n\n```\n\n## Storage\n\nThere is a Batcan::Storage module that can be utilized along with activerecord/mongoid and the sentient_user gems to provide\nsecure persistance methods at the model layer. For example:\n\n```ruby\nclass User\n    include Mongoid\n    include SentientUser\n    include Batcan::Canable\n\n    field :role\nend\n\nclass Team\n    include Mongoid\n    include Batcan::Permissible\n    include Batcan::Storable\n\n    field :name\n\n    # allow admin users to create/update teams\n    permission :save do |team, user|\n        user.role == :admin\n    end\nend\n\nuser = User.first.make_current\nteam = Team.first\nteam.name = 'foo'\nteam.store! # will raise an error if user is not an admin\n```\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'batcan'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install batcan\n\n## Usage\n\nTODO: Write usage instructions here\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/batcan/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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewars%2Fbatcan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewars%2Fbatcan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewars%2Fbatcan/lists"}