Permalink
Browse files

renamed gem to 'authority'

  • Loading branch information...
1 parent 1b4be57 commit 3a24300e4760a1378f92dd342fab65a541b590f7 Nathan Long committed Mar 12, 2012
View
@@ -1 +1 @@
-rvm use --create default@model_citizen
+rvm use --create default@authority
View
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
-# Specify your gem's dependencies in model_citizen.gemspec
+# Specify your gem's dependencies in authority.gemspec
gemspec
gem 'rspec', '>= 2.8.0'
View
@@ -1,14 +1,14 @@
-# ModelCitizen
+# Authority
## SUPER ALPHA VERSION
## Overview
-ModelCitizen gives you a clean and easy way to say, in your Rails app, **who** is allowed to do **what** with your models.
+Authority gives you a clean and easy way to say, in your Rails app, **who** is allowed to do **what** with your models.
It assumes that you already have some kind of user object in your application.
-The goals of ModelCitizen are:
+The goals of Authority are:
- To allow broad, class-level rules. Examples:
- "Basic users cannot delete **any** Widget."
@@ -29,15 +29,15 @@ The goals of ModelCitizen are:
Add this line to your application's Gemfile:
- gem 'model_citizen'
+ gem 'authority'
And then execute:
$ bundle
Or install it yourself as:
- $ gem install model_citizen
+ $ gem install authority
## How it works
@@ -52,11 +52,11 @@ In broad terms, the authorization process flows like this:
### Users
-Your user model (whatever you call it) should `include ModelCitizen::UserAbilities`. This defines methods like `can_edit?(resource)`, which are just nice shortcuts for `resource.editable_by?(user)`. (TODO: Add this module).
+Your user model (whatever you call it) should `include Authority::UserAbilities`. This defines methods like `can_edit?(resource)`, which are just nice shortcuts for `resource.editable_by?(user)`. (TODO: Add this module).
### Models
-In your models, simply `include ModelCitizen::Abilities`. This sets up both class-level and instance-level methods like `creatable_by?(user)`, etc, all of which delegate to the model's corresponding authorizer. For example, the `Rabbit` model would delegate to `RabbitAuthorizer`.
+In your models, simply `include Authority::Abilities`. This sets up both class-level and instance-level methods like `creatable_by?(user)`, etc, all of which delegate to the model's corresponding authorizer. For example, the `Rabbit` model would delegate to `RabbitAuthorizer`.
### Controllers
@@ -79,18 +79,18 @@ If you need to check some attributes of a model instance to decide if an action
Authorizers should be added under `app/authorizers`, one for each of your models. Each authorizer should correspond to a single model. So if you have `app/models/laser_cannon.rb`, you should have, at minimum:
# app/authorizers/laser_cannon_authorizer.rb
- class LaserCannonAuthorizer < ModelCitizen::Authorizer
+ class LaserCannonAuthorizer < Authority::Authorizer
end
-These are where your actual authorization logic goes. You do have to specify your own business rules, but ModelCitizen comes with the following baked in:
+These are where your actual authorization logic goes. You do have to specify your own business rules, but Authority comes with the following baked in:
-- All class-level methods defined on `ModelCitizen::Authorizer` return false by default; you must override them in your Authorizers to grant permissions. This whitelisting approach will keep you from accidentally allowing things you didn't intend.
-- All instance-level methods defined on `ModelCitizen::Authorizer` call their corresponding class-level method by default.
+- All class-level methods defined on `Authority::Authorizer` return false by default; you must override them in your Authorizers to grant permissions. This whitelisting approach will keep you from accidentally allowing things you didn't intend.
+- All instance-level methods defined on `Authority::Authorizer` call their corresponding class-level method by default.
This combination means that, with this code:
# app/authorizers/laser_cannon_authorizer.rb
- class LaserCannonAuthorizer < ModelCitizen::Authorizer
+ class LaserCannonAuthorizer < Authority::Authorizer
end
... you can already do the following:
@@ -101,7 +101,7 @@ This combination means that, with this code:
If you update your authorizer as follows:
# app/authorizers/laser_cannon_authorizer.rb
- class LaserCannonAuthorizer < ModelCitizen::Authorizer
+ class LaserCannonAuthorizer < Authority::Authorizer
def self.creatable_by?(user) # class-level permission
true
@@ -123,6 +123,8 @@ If you update your authorizer as follows:
- Add a module, to be included in whatever user class an app has, which defines all the `can_(verb)` methods.
- Determine exact syntax for checking rules during a controller action.
+- Add ability to customize default authorization
+- Add customizable logger for authorization violations
## Contributing
View
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/authority/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Nathan Long", "Adam Hunter"]
+ gem.email = ["nathanmlong@gmail.com", "adamhunter@me.com"]
+ gem.description = %q{Gem for managing authorization on model actions in Rails}
+ gem.summary = %q{Authority gives you a clean and easy way to say, in your Rails app, **who** is allowed to do **what** with your models.}
+ gem.homepage = "https://github.com/nathanl/authority"
+
+ gem.add_dependency "rails", ">= 3.0.0"
+ gem.add_development_dependency "bundler", ">= 1.0.0"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "model_citizen"
+ gem.require_paths = ["lib"]
+ gem.version = Authority::VERSION
+end
@@ -2,10 +2,10 @@
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'
-module ModelCitizen
+module Authority
ADJECTIVES = %w[creatable readable updatable deletable]
end
-require 'model_citizen/abilities'
-require 'model_citizen/authorizer'
-require 'model_citizen/version'
+require 'authority/abilities'
+require 'authority/authorizer'
+require 'authority/version'
@@ -1,4 +1,4 @@
-module ModelCitizen
+module Authority
module Abilities
extend ActiveSupport::Concern
@@ -1,4 +1,4 @@
-module ModelCitizen
+module Authority
class Authorizer
attr_reader :resource
@@ -1,3 +1,3 @@
-module ModelCitizen
+module Authority
VERSION = "0.0.1"
end
View
@@ -1,20 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/model_citizen/version', __FILE__)
-
-Gem::Specification.new do |gem|
- gem.authors = ["Nathan Long"]
- gem.email = ["nathan.long@tma1.com"]
- gem.description = %q{TODO: Write a gem description}
- gem.summary = %q{TODO: Write a gem summary}
- gem.homepage = ""
-
- gem.add_dependency "rails", ">= 3.0.0"
- gem.add_development_dependency "bundler", ">= 1.0.0"
-
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- gem.files = `git ls-files`.split("\n")
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.name = "model_citizen"
- gem.require_paths = ["lib"]
- gem.version = ModelCitizen::VERSION
-end
@@ -2,7 +2,7 @@
require 'support/ability_model'
require 'support/actor'
-describe ModelCitizen::Abilities do
+describe Authority::Abilities do
before :each do
@actor = Actor.new
@@ -38,7 +38,7 @@
describe "class methods" do
- ModelCitizen::ADJECTIVES.each do |adjective|
+ Authority::ADJECTIVES.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
@@ -61,7 +61,7 @@
@authorizer = AbilityModel.authorizer.new(@ability_model)
end
- ModelCitizen::ADJECTIVES.each do |adjective|
+ Authority::ADJECTIVES.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
@@ -1,11 +1,11 @@
require 'spec_helper'
require 'support/ability_model'
-describe ModelCitizen::Authorizer do
+describe Authority::Authorizer do
before :each do
@ability_model = AbilityModel.new
- @authorizer = ModelCitizen::Authorizer.new(@ability_model)
+ @authorizer = Authority::Authorizer.new(@ability_model)
end
it "should take a resource instance in its initializer" do
@@ -14,11 +14,11 @@
describe "class methods" do
- ModelCitizen::ADJECTIVES.each do |adjective|
+ Authority::ADJECTIVES.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
- ModelCitizen::Authorizer.should respond_to(method_name)
+ Authority::Authorizer.should respond_to(method_name)
end
end
@@ -27,7 +27,7 @@
describe "instance methods" do
- ModelCitizen::ADJECTIVES.each do |adjective|
+ Authority::ADJECTIVES.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe Authority do
+ it "should have a constant of abilities" do
+ Authority::ADJECTIVES.should be_an(Array)
+ end
+end
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe ModelCitizen do
-end
View
@@ -1,6 +1,6 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'rspec'
-require 'model_citizen'
+require 'authority'
RSpec.configure do |config|
config.mock_with :rspec
@@ -1,6 +1,6 @@
class AbilityModel
- include ModelCitizen::Abilities
+ include Authority::Abilities
end
-class AbilityModelAuthorizer < ModelCitizen::Authorizer
+class AbilityModelAuthorizer < Authority::Authorizer
end

0 comments on commit 3a24300

Please sign in to comment.