mongoid_ability 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b22befcca304fbace4cd22f72704b7d5a109a0b
4
- data.tar.gz: 56a19a326bdb60d7d462558c51cd0d7196146d8b
3
+ metadata.gz: d14cea1999e69a46f9ab6999787d58498fa59984
4
+ data.tar.gz: ace3845f26fd9cf1ccb8f6572005ef9584448af9
5
5
  SHA512:
6
- metadata.gz: 740466111f499e95e981197abc5567740c7ecb829126a863bf6720cddadb5f4b9a75ad9fc851f93bfecb8e90e55ce73a40b20ee8d7741b893412270a7ac71c3b
7
- data.tar.gz: 83f00db0cdb31b4f1ebd024c40f5b1390059a0b686119bcf7e27d97a081f4e5d7208286920cf929b55253e73450182201133c63c1dcf882bc10b4ca24e2ab35b
6
+ metadata.gz: b7c6a973a830ebac23878e9fdc05174e518c1bcd3c889fd860ea03af7edb12ba10921fd852e75b09375a39420e8d3738795e5d036f5e158fe229697276a0dee4
7
+ data.tar.gz: fd015fa0b0e23d86fc7f4689b931d0a08c96af7cc30262d9f4d51dd4954fd3e7631a073091320eddf3be247abb7a98ed77391a5288d220fac35168aadc249df8
@@ -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, attrs={}
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( { subject_type: self.to_s, action: action, outcome: outcome }.merge(attrs))
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 }
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
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.10
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-07 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan