mongoid_ability 0.1.10 → 0.1.11
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 -3
- data/lib/mongoid_ability/subject.rb +2 -2
- data/lib/mongoid_ability/version.rb +1 -1
- 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: d14cea1999e69a46f9ab6999787d58498fa59984
|
4
|
+
data.tar.gz: ace3845f26fd9cf1ccb8f6572005ef9584448af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7c6a973a830ebac23878e9fdc05174e518c1bcd3c889fd860ea03af7edb12ba10921fd852e75b09375a39420e8d3738795e5d036f5e158fe229697276a0dee4
|
7
|
+
data.tar.gz: fd015fa0b0e23d86fc7f4689b931d0a08c96af7cc30262d9f4d51dd4954fd3e7631a073091320eddf3be247abb7a98ed77391a5288d220fac35168aadc249df8
|
data/lib/mongoid_ability/lock.rb
CHANGED
@@ -7,6 +7,7 @@ module MongoidAbility
|
|
7
7
|
base.class_eval do
|
8
8
|
field :action, type: Symbol, default: :read
|
9
9
|
field :outcome, type: Boolean, default: false
|
10
|
+
field :options, type: Hash, default: {}
|
10
11
|
|
11
12
|
belongs_to :subject, polymorphic: true, touch: true
|
12
13
|
|
@@ -41,11 +42,16 @@ module MongoidAbility
|
|
41
42
|
end
|
42
43
|
|
43
44
|
# calculates outcome as if this lock is not present
|
44
|
-
def inherited_outcome
|
45
|
-
return calculated_outcome unless owner.present?
|
45
|
+
def inherited_outcome options=default_options
|
46
|
+
return calculated_outcome(options) unless owner.present?
|
46
47
|
cloned_owner = owner.clone
|
47
48
|
cloned_owner.locks_relation = cloned_owner.locks_relation - [self]
|
48
|
-
MongoidAbility::Ability.new(cloned_owner).can? action, (subject.present? ? subject : subject_class)
|
49
|
+
MongoidAbility::Ability.new(cloned_owner).can? action, (subject.present? ? subject : subject_class), options
|
50
|
+
end
|
51
|
+
|
52
|
+
# this is used when calculating inherited outcome
|
53
|
+
def default_options
|
54
|
+
{}
|
49
55
|
end
|
50
56
|
|
51
57
|
# ---------------------------------------------------------------------
|
@@ -16,14 +16,14 @@ module MongoidAbility
|
|
16
16
|
@default_locks = locks
|
17
17
|
end
|
18
18
|
|
19
|
-
def default_lock lock_cls, action, outcome,
|
19
|
+
def default_lock lock_cls, action, outcome, options={}
|
20
20
|
unless is_root_class?
|
21
21
|
unless root_class.has_default_lock_for_action?(action)
|
22
22
|
raise StandardError, "action is not defined on root class (#{root_class})"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
lock = lock_cls.new(
|
26
|
+
lock = lock_cls.new( subject_type: self.to_s, action: action, outcome: outcome, options: options )
|
27
27
|
|
28
28
|
# remove any existing locks
|
29
29
|
if existing_lock = default_locks.detect{ |l| l.action == lock.action }
|
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.11
|
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-09-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|