allowance 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -1
- data/lib/allowance/permissions.rb +1 -1
- data/lib/allowance/version.rb +1 -1
- data/lib/allowance.rb +3 -0
- data/spec/allowance_spec.rb +17 -0
- data/spec/permissions_spec.rb +15 -2
- metadata +10 -8
data/README.md
CHANGED
@@ -1,6 +1,50 @@
|
|
1
1
|
# Allowance
|
2
2
|
|
3
|
-
|
3
|
+
Allowance is a general-use permission management library that can be used
|
4
|
+
in any framework or application.
|
5
|
+
|
6
|
+
A simple Example:
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
p = Allowance.define do |can|
|
10
|
+
can.sing!
|
11
|
+
can.play!
|
12
|
+
end
|
13
|
+
|
14
|
+
p.sing? # true
|
15
|
+
p.play? # true
|
16
|
+
p.dance? # false
|
17
|
+
```
|
18
|
+
|
19
|
+
You can specify permissions on objects (and their classes), too:
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
p = Allowance.define do |can|
|
23
|
+
# Everyone can view posts that have been published
|
24
|
+
can.view! Post, :published => true
|
25
|
+
|
26
|
+
# Post owners can delete their own posts
|
27
|
+
can.delete! Post, :user_id => current_user.id
|
28
|
+
|
29
|
+
# Admin users can view and delete all posts
|
30
|
+
if current_user.admin?
|
31
|
+
can.view! Post
|
32
|
+
can.delete! Post
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Instead of condition hashes, you can specify lambdas. This is great for model
|
38
|
+
classes that are ActiveModel based (eg. ActiveRecord, Mongoid etc.):
|
39
|
+
|
40
|
+
``` ruby
|
41
|
+
p = Allowance.define do |can|
|
42
|
+
# Everyone can view posts that have been published
|
43
|
+
can.view! Post, lambda { |posts| posts.visible_posts }
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
More documentation coming up soon.
|
4
48
|
|
5
49
|
## Installation
|
6
50
|
|
data/lib/allowance/version.rb
CHANGED
data/lib/allowance.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Allowance
|
4
|
+
describe "#define" do
|
5
|
+
it "should return an instance of Allowance::Permissions" do
|
6
|
+
Allowance.define.should be_kind_of(Allowance::Permissions)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should make sure the passed block is executed" do
|
10
|
+
p = Allowance.define do |allow|
|
11
|
+
allow.sing!
|
12
|
+
end
|
13
|
+
|
14
|
+
insist p.sing?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/permissions_spec.rb
CHANGED
@@ -21,6 +21,19 @@ module Allowance
|
|
21
21
|
insist p.sing?
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should not modify the block's scope" do
|
25
|
+
yup = true
|
26
|
+
nope = false
|
27
|
+
|
28
|
+
p = Permissions.new do |can|
|
29
|
+
can.sing! if yup
|
30
|
+
can.dance! if nope
|
31
|
+
end
|
32
|
+
|
33
|
+
insist p.sing?
|
34
|
+
refuse p.dance?
|
35
|
+
end
|
36
|
+
|
24
37
|
it "should allow verbs and objects" do
|
25
38
|
subject.update! SomeClass
|
26
39
|
|
@@ -46,7 +59,7 @@ module Allowance
|
|
46
59
|
|
47
60
|
model_class.should_receive(:find).and_return(model_instance)
|
48
61
|
|
49
|
-
subject.view! model_class, lambda { some_scope }
|
62
|
+
subject.view! model_class, lambda { |r| r.some_scope }
|
50
63
|
|
51
64
|
insist subject.view? model_instance
|
52
65
|
end
|
@@ -56,7 +69,7 @@ module Allowance
|
|
56
69
|
model = mock
|
57
70
|
model.should_receive(:some_scope).and_return(scoped_model = mock)
|
58
71
|
|
59
|
-
subject.view! model, lambda { some_scope }
|
72
|
+
subject.view! model, lambda { |r| r.some_scope }
|
60
73
|
subject.scoped_model(:view, model).should == scoped_model
|
61
74
|
end
|
62
75
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allowance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70168031557120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70168031557120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70168031554220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70168031554220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: watchr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70168031553600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70168031553600
|
47
47
|
description: A generic, but decidedly awesome authorization control layer.
|
48
48
|
email:
|
49
49
|
- hendrik@mans.de
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/allowance.rb
|
64
64
|
- lib/allowance/permissions.rb
|
65
65
|
- lib/allowance/version.rb
|
66
|
+
- spec/allowance_spec.rb
|
66
67
|
- spec/permissions_spec.rb
|
67
68
|
- spec/spec_helper.rb
|
68
69
|
homepage: ''
|
@@ -90,6 +91,7 @@ signing_key:
|
|
90
91
|
specification_version: 3
|
91
92
|
summary: A generic, but decidedly awesome authorization control layer.
|
92
93
|
test_files:
|
94
|
+
- spec/allowance_spec.rb
|
93
95
|
- spec/permissions_spec.rb
|
94
96
|
- spec/spec_helper.rb
|
95
97
|
has_rdoc:
|