mongoid_ability 0.1.0 → 0.1.1

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: 5c94126d8c7b257f7a07a4523aa5967a197e4ed5
4
- data.tar.gz: 0a7daeea08caa81ed98c488185928942eb144aa4
3
+ metadata.gz: bde67f16382046638b7c44bbffaee16d487e249e
4
+ data.tar.gz: 865cfbd05868412373e72e4e026636a04292d710
5
5
  SHA512:
6
- metadata.gz: bac9709c73d4d227bdb3786d8de7ffdda5aea899f294c9e3adbf0d7f543832f2c82266c41e73ef7f7bc938d409e2ab8dbafd8402c21545923745287b213411dc
7
- data.tar.gz: 9174b6fa5c46d17cd480d1fd468874d1c67cef6562e2fd77f43406fb5e392e0d0cbe56fd32ba505534d7ffbcbbda810e426f66cf954f4aef2df56033938df930
6
+ metadata.gz: 7ae18b864f57c2b87a8e19bbcb2995dfc2435840eb688bb1c34b7adeecd7113800afdabc3b7da9a602a986384efcc0ccb35ff8769a5879b07d886757b85966be
7
+ data.tar.gz: f35c6dda2fa87911e840856963bc84f8b85e0c00e289051cde6dc457352bcc7616528e8e179659640827f639e7c4083b2b2f16bb45f13d287657fe952e8259fa
@@ -26,10 +26,12 @@ module MongoidAbility
26
26
  subject_class = subject_type.to_s.constantize
27
27
  outcome = nil
28
28
  options ||= {}
29
+
29
30
  subject_class.self_and_ancestors_with_default_locks.each do |cls|
30
31
  outcome = ResolveInheritedLocks.call(owner, action, cls, subject, options)
31
32
  break if outcome != nil
32
33
  end
34
+
33
35
  outcome
34
36
  end
35
37
 
@@ -8,12 +8,16 @@ module MongoidAbility
8
8
  # =====================================================================
9
9
 
10
10
  def call
11
- if defined? Rails
12
- # FIXME: this is a bit of a dirty hack, since the marshalling of criteria does not preserve the embedded attributes
13
- Rails.cache.fetch( [ 'ability-query', base_class, ability.cache_key, action, ability.options_cache_key(options) ] ) { _call }.tap { |criteria| criteria.embedded = base_criteria.embedded }
14
- else
15
- _call
16
- end
11
+ _call
12
+
13
+ # if defined? Rails
14
+ # # FIXME: this is a bit of a dirty hack, since the marshalling of criteria does not preserve the embedded attributes
15
+ # Rails.cache.fetch( [ 'ability-query', base_class, ability.cache_key, action, ability.options_cache_key(options) ] ) do
16
+ # _call
17
+ # end.tap { |c| c.embedded = base_criteria.embedded }
18
+ # else
19
+ # _call
20
+ # end
17
21
  end
18
22
 
19
23
  private # =============================================================
@@ -3,21 +3,29 @@ module MongoidAbility
3
3
 
4
4
  def self.included base
5
5
  base.extend ClassMethods
6
+ base.class_eval do
7
+ end
6
8
  end
7
9
 
8
10
  # ---------------------------------------------------------------------
9
11
 
10
12
  module ClassMethods
11
13
  def default_locks
12
- @default_locks ||= DefaultLocksExtension.new
14
+ @default_locks ||= []
13
15
  end
14
16
 
15
17
  def default_locks= locks
16
- @default_locks = DefaultLocksExtension.new(locks)
18
+ @default_locks = locks
17
19
  end
18
20
 
19
21
  def default_lock lock_cls, action, outcome, attrs={}
20
- default_locks << lock_cls.new( { subject_type: self.to_s, action: action, outcome: outcome }.merge(attrs))
22
+ lock = lock_cls.new( { subject_type: self.to_s, action: action, outcome: outcome }.merge(attrs))
23
+
24
+ if existing_lock = default_locks.detect{ |l| l.action.to_s == lock.action.to_s }
25
+ default_locks.delete(existing_lock)
26
+ end
27
+
28
+ default_locks.push lock
21
29
  end
22
30
 
23
31
  def self_and_ancestors_with_default_locks
@@ -33,26 +41,5 @@ module MongoidAbility
33
41
  end
34
42
  end
35
43
 
36
- # ---------------------------------------------------------------------
37
-
38
- require 'forwardable'
39
- class DefaultLocksExtension
40
- extend Forwardable
41
- def_delegators :@default_locks, :any?, :collect, :delete, :detect, :first, :map, :push, :select
42
-
43
- attr_reader :default_locks
44
-
45
- def initialize default_locks=[]
46
- @default_locks = default_locks
47
- end
48
-
49
- def << lock
50
- if existing_lock = self.detect{ |l| l.action.to_s == lock.action.to_s }
51
- @default_locks.delete(existing_lock)
52
- end
53
- @default_locks.push lock
54
- end
55
- end
56
-
57
44
  end
58
45
  end
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_ability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna