mongoid_ability 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/lib/mongoid_ability/lock.rb +9 -8
- data/lib/mongoid_ability/subject.rb +5 -1
- data/lib/mongoid_ability/version.rb +1 -1
- data/test/mongoid_ability/subject_test.rb +13 -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: dd50f6141566a2e2c5d2814db0a66d5bd7f8a419
|
4
|
+
data.tar.gz: 4410f6d3f4991cdb145c1f68ca8d80c1c8943562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27e701a3f9991f7d03aa13e669e9764c85f4f233d5d15b759c044ccc10b2574dc474d62728dcf88de7cc25bb7e064cd8f04851f87780359673a6124490059df5
|
7
|
+
data.tar.gz: bbaeeaa89f8166741eb5c8f90d16bd00bcaede8c116099bea982446dc39b0824234acf1ada6c1eaaa978abc6bc9c7559102656c8580a7e263e71d33f862f8bc6
|
data/lib/mongoid_ability/lock.rb
CHANGED
@@ -8,16 +8,17 @@ module MongoidAbility
|
|
8
8
|
field :outcome, type: Boolean, default: false
|
9
9
|
|
10
10
|
# ---------------------------------------------------------------------
|
11
|
-
|
11
|
+
|
12
12
|
belongs_to :subject, polymorphic: true, touch: true
|
13
13
|
|
14
14
|
# ---------------------------------------------------------------------
|
15
|
-
|
15
|
+
|
16
|
+
# TODO: validate that action is defined on subject or its superclasses
|
16
17
|
validates :action, presence: true, uniqueness: { scope: [ :subject_type, :subject_id, :outcome ] }
|
17
18
|
validates :outcome, presence: true
|
18
19
|
|
19
20
|
# ---------------------------------------------------------------------
|
20
|
-
|
21
|
+
|
21
22
|
scope :for_action, -> action { where(action: action.to_sym) }
|
22
23
|
|
23
24
|
scope :for_subject_type, -> subject_type { where(subject_type: subject_type.to_s) }
|
@@ -30,18 +31,18 @@ module MongoidAbility
|
|
30
31
|
end
|
31
32
|
|
32
33
|
# =====================================================================
|
33
|
-
|
34
|
+
|
34
35
|
module ClassMethods
|
35
36
|
end
|
36
37
|
|
37
38
|
# =====================================================================
|
38
|
-
|
39
|
+
|
39
40
|
def calculated_outcome
|
40
41
|
self.outcome
|
41
42
|
end
|
42
43
|
|
43
44
|
# ---------------------------------------------------------------------
|
44
|
-
|
45
|
+
|
45
46
|
def open?
|
46
47
|
self.calculated_outcome == true
|
47
48
|
end
|
@@ -51,7 +52,7 @@ module MongoidAbility
|
|
51
52
|
end
|
52
53
|
|
53
54
|
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
+
|
55
56
|
def class_lock?
|
56
57
|
!id_lock?
|
57
58
|
end
|
@@ -61,7 +62,7 @@ module MongoidAbility
|
|
61
62
|
end
|
62
63
|
|
63
64
|
# ---------------------------------------------------------------------
|
64
|
-
|
65
|
+
|
65
66
|
def conditions
|
66
67
|
res = { _type: subject_type }
|
67
68
|
res = res.merge(_id: subject_id) if subject_id.present?
|
@@ -24,7 +24,11 @@ module MongoidAbility
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def default_lock action, outcome
|
27
|
-
default_locks
|
27
|
+
if existing_lock = default_locks.detect{ |l| l.action.to_s == action.to_s }
|
28
|
+
existing_lock.outcome = outcome
|
29
|
+
else
|
30
|
+
default_locks << lock_class_name.constantize.new(subject_type: self, action: action, outcome: outcome)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
# ---------------------------------------------------------------------
|
@@ -52,6 +52,19 @@ module MongoidAbility
|
|
52
52
|
lock.subject_id.must_be_nil
|
53
53
|
lock.action.must_equal :read
|
54
54
|
end
|
55
|
+
|
56
|
+
describe 'when trying to insert another lock for same action' do
|
57
|
+
before do
|
58
|
+
subject.class.default_lock :read, false
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not create duplicate' do
|
62
|
+
subject.class.default_locks.select{ |l| l.action == :read }.length.must_equal 1
|
63
|
+
end
|
64
|
+
it 'sets the new outcome' do
|
65
|
+
subject.class.default_locks.select{ |l| l.action == :read }.first.outcome.must_equal false
|
66
|
+
end
|
67
|
+
end
|
55
68
|
end
|
56
69
|
|
57
70
|
# =====================================================================
|
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.0.
|
4
|
+
version: 0.0.9
|
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-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|