rails-canhaz 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -62,8 +62,8 @@ article = Article.find(1337)
62
62
 
63
63
  user.can?(:read, article) # Can the user read this article? false for now
64
64
 
65
- user.can(:read, article) # Ok, so the user can read this article
66
- user.can(:edit, article) # He can edit it as well
65
+ user.can!(:read, article) # Ok, so the user can read this article
66
+ user.can!(:edit, article) # He can edit it as well
67
67
 
68
68
  user.can?(:read, article) # Will be true
69
69
 
@@ -73,7 +73,7 @@ artice.subjects_with_permission(User, :read) # Will return all the users hat are
73
73
 
74
74
  #You can also remove permissions
75
75
 
76
- user.cannot(:read, article)
76
+ user.cannot!(:read, article)
77
77
 
78
78
  ```
79
79
 
@@ -2,12 +2,20 @@ module CanHaz
2
2
  module ModelExtensions
3
3
  module Subject
4
4
 
5
+ # Alias for {#can!}
6
+ #
7
+ # @deprecated Please use {#can!} instead
8
+ def can(permission, object)
9
+ warn "[DEPRECATION] can is deprecated and will be removed in a future release, please use `can!` instead"
10
+ self.can!(permission, object)
11
+ end
12
+
5
13
  # Creates a permission on a given object
6
14
  #
7
15
  # @param permission [String, Symbol] The identifier of the permission
8
16
  # @param object [ActiveRecord::Base] The model on which the permission is effective
9
17
  # @return [Bool] True if the role was successfully created, false if it was already present
10
- def can(permission, object)
18
+ def can!(permission, object)
11
19
  raise Exceptions::NotACanHazObject unless object.canhaz_object?
12
20
  CanHazPermission.new({
13
21
  :csubject_id => self.id,
@@ -28,12 +36,20 @@ module CanHaz
28
36
  CanHazPermission.find_permission(self, object, permission) != nil
29
37
  end
30
38
 
39
+ # Alias for {#cannot!}
40
+ #
41
+ # @deprecated Please use {#cannot!} instead
42
+ def cannot(permission, object)
43
+ warn "[DEPRECATION] cannot is deprecated and will be removed in a future release, please use `cannot!` instead"
44
+ self.cannot!(permission, object)
45
+ end
46
+
31
47
  # Removes a permission on a given object
32
48
  #
33
49
  # @param permission [String, Symbol] The identifier of the permission
34
50
  # @param object [ActiveRecord::Base] The model on which the permission is effective
35
51
  # @return [Bool] True if the role was successfully removed, false if it did not exist
36
- def cannot(permission, object)
52
+ def cannot!(permission, object)
37
53
  permission = CanHazPermission.find_permission(self, object, permission)
38
54
  return false if permission.nil?
39
55
  permission.destroy and return true
data/rails-canhaz.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rails-canhaz'
3
- s.version = '0.3.0'
4
- s.date = '2012-05-20'
3
+ s.version = '0.4.0'
4
+ s.date = '2012-05-30'
5
5
  s.summary = "A simple gem for managing permissions between rails models"
6
6
  s.description = "A simple gem for managing permissions between rails models"
7
7
  s.authors = ["Adrien Siami (Intrepidd)"]
data/test/test_canhaz.rb CHANGED
@@ -39,11 +39,11 @@ class CanHazTest < Test::Unit::TestCase
39
39
  object = ObjectModel.new
40
40
 
41
41
  assert_raise CanHaz::Exceptions::NotACanHazObject do
42
- subject.can(:whatever, foo)
42
+ subject.can!(:whatever, foo)
43
43
  end
44
44
 
45
45
  assert_nothing_raised RuntimeError do
46
- subject.can(:whatever, object)
46
+ subject.can!(:whatever, object)
47
47
  end
48
48
 
49
49
  assert_raise CanHaz::Exceptions::NotACanHazObject do
@@ -69,11 +69,11 @@ class CanHazTest < Test::Unit::TestCase
69
69
  assert object.accessible_by?(subject, :foo) == false
70
70
  assert object.accessible_by?(subject, :bar) == false
71
71
 
72
- assert subject.can(:foo, object)
73
- assert subject.can(:bar, object)
72
+ assert subject.can!(:foo, object)
73
+ assert subject.can!(:bar, object)
74
74
 
75
- assert subject.can(:foo, object) == false
76
- assert subject.can(:bar, object) == false
75
+ assert subject.can!(:foo, object) == false
76
+ assert subject.can!(:bar, object) == false
77
77
 
78
78
  assert subject.can?(:foo, object)
79
79
  assert subject.can?(:bar, object)
@@ -99,15 +99,15 @@ class CanHazTest < Test::Unit::TestCase
99
99
  object.save
100
100
 
101
101
  assert subject.can?(:foo, object) == false
102
- assert subject.cannot(:foo, object) == false
102
+ assert subject.cannot!(:foo, object) == false
103
103
 
104
- subject.can(:foo, object)
105
- subject.can(:bar, object)
104
+ subject.can!(:foo, object)
105
+ subject.can!(:bar, object)
106
106
 
107
107
  assert subject.can?(:foo, object)
108
108
  assert subject.can?(:bar, object)
109
109
 
110
- assert subject.cannot(:foo, object) == true
110
+ assert subject.cannot!(:foo, object) == true
111
111
 
112
112
  assert subject.can?(:foo, object) == false
113
113
  assert subject.can?(:bar, object) == true
@@ -125,9 +125,9 @@ class CanHazTest < Test::Unit::TestCase
125
125
  s2.save
126
126
  s3.save
127
127
 
128
- s1.can(:foo, object)
129
- s2.can(:bar, object)
130
- s3.can(:foo, object)
128
+ s1.can!(:foo, object)
129
+ s2.can!(:bar, object)
130
+ s3.can!(:foo, object)
131
131
 
132
132
  foo = object.subjects_with_permission(SubjectModel, :foo)
133
133
 
@@ -135,7 +135,7 @@ class CanHazTest < Test::Unit::TestCase
135
135
  assert foo.include?(s2) == false
136
136
  assert foo.include?(s3) == true
137
137
 
138
- s3.cannot(:foo, object)
138
+ s3.cannot!(:foo, object)
139
139
 
140
140
  foo = object.subjects_with_permission(SubjectModel, :foo)
141
141
 
@@ -165,12 +165,12 @@ class CanHazTest < Test::Unit::TestCase
165
165
  object2 = ObjectModel.new
166
166
  object2.save
167
167
 
168
- subject.can(:foo, object1)
169
- subject.can(:bar, object1)
170
- subject.can(:foo, object2)
171
- subject.can(:bar, object2)
168
+ subject.can!(:foo, object1)
169
+ subject.can!(:bar, object1)
170
+ subject.can!(:foo, object2)
171
+ subject.can!(:bar, object2)
172
172
 
173
- subject2.can(:foo, object1)
173
+ subject2.can!(:foo, object1)
174
174
 
175
175
  subject.can_do_nothing
176
176
 
@@ -197,12 +197,12 @@ class CanHazTest < Test::Unit::TestCase
197
197
  o1.save
198
198
  o2.save
199
199
 
200
- s1.can(:foo, o1)
201
- s1.can(:foo, o2)
202
- s1.can(:bar, o2)
200
+ s1.can!(:foo, o1)
201
+ s1.can!(:foo, o2)
202
+ s1.can!(:bar, o2)
203
203
 
204
- s2.can(:bar, o1)
205
- s2.can(:foo, o2)
204
+ s2.can!(:bar, o1)
205
+ s2.can!(:foo, o2)
206
206
 
207
207
  result = CanHazPermission.can?([s1, s2], :foo, [o1, o2])
208
208
 
@@ -225,8 +225,8 @@ class CanHazTest < Test::Unit::TestCase
225
225
 
226
226
  id = s.id
227
227
 
228
- s.can(:foo, o)
229
- s.can(:bar, o)
228
+ s.can!(:foo, o)
229
+ s.can!(:bar, o)
230
230
 
231
231
  s.destroy
232
232
 
@@ -240,8 +240,8 @@ class CanHazTest < Test::Unit::TestCase
240
240
 
241
241
  id = o.id
242
242
 
243
- s.can(:foo, o)
244
- s.can(:bar, o)
243
+ s.can!(:foo, o)
244
+ s.can!(:bar, o)
245
245
 
246
246
  o.destroy
247
247
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-canhaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -77,3 +77,4 @@ signing_key:
77
77
  specification_version: 3
78
78
  summary: A simple gem for managing permissions between rails models
79
79
  test_files: []
80
+ has_rdoc: