mongoid_ability 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid_ability/ability.rb +14 -1
- data/lib/mongoid_ability/version.rb +1 -1
- data/test/mongoid_ability/lock_test.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e288828c255c06a145d7c88a11c5b0b49c8f80c
|
4
|
+
data.tar.gz: d232f755214a1234c110c8bc12921c044c879165
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414d902820c8026e7f844347964954c9c7cd26f8ab178a65f9d33eb54b88dd8d84feea832fdb15e1e82d32c1c5a88fa220cde2141f0ed00fc38882ffed429117
|
7
|
+
data.tar.gz: 68c103c14039e84dc3401dbbd2360f42a45557e960a719f334f5b27e7ed78497f3d43e27a0728910746cbdb025e0c82041992758cf3d1e731adae4203f15c71b
|
@@ -11,7 +11,7 @@ module MongoidAbility
|
|
11
11
|
|
12
12
|
can do |action, subject_type, subject, options|
|
13
13
|
_can(action, subject_type, subject, options)
|
14
|
-
|
14
|
+
|
15
15
|
# if defined? Rails
|
16
16
|
# ::Rails.cache.fetch( [ cache_key ] + cache_keys(action, subject_type, subject, options) ) do
|
17
17
|
# _can(action, subject_type, subject, options)
|
@@ -61,5 +61,18 @@ module MongoidAbility
|
|
61
61
|
owner.inherit_from_relation.map(&:cache_key)
|
62
62
|
end
|
63
63
|
|
64
|
+
# ---------------------------------------------------------------------
|
65
|
+
|
66
|
+
# lambda for easy permission checking:
|
67
|
+
# .select(¤t_ability.can_read)
|
68
|
+
# .select(¤t_ability.can_update)
|
69
|
+
# .select(¤t_ability.can_destroy)
|
70
|
+
# etc.
|
71
|
+
def method_missing name, *args
|
72
|
+
return super unless name.to_s =~ /\Acan_/
|
73
|
+
return unless action = name.to_s.gsub(/\Acan_/, '').to_sym
|
74
|
+
lambda { |doc| can? action, doc }
|
75
|
+
end
|
76
|
+
|
64
77
|
end
|
65
78
|
end
|
@@ -35,6 +35,20 @@ module MongoidAbility
|
|
35
35
|
|
36
36
|
# ---------------------------------------------------------------------
|
37
37
|
|
38
|
+
describe '.subject_id' do
|
39
|
+
it 'converts legal id String to BSON' do
|
40
|
+
id = BSON::ObjectId.new
|
41
|
+
MyLock.for_subject_id(id.to_s).selector['subject_id'].must_be_kind_of BSON::ObjectId
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'converts empty String to nil' do
|
45
|
+
id = ''
|
46
|
+
MyLock.for_subject_id(id.to_s).selector['subject_id'].must_equal nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# ---------------------------------------------------------------------
|
51
|
+
|
38
52
|
describe '#criteria' do
|
39
53
|
let(:open_subject_type_lock) { MyLock.new(subject_type: MySubject, action: :read, outcome: true) }
|
40
54
|
let(:closed_subject_type_lock) { MyLock.new(subject_type: MySubject, action: :read, outcome: false) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_ability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|