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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f2f18aa441d6339b6ddc2cd386d443efcd31df4
4
- data.tar.gz: 5822292aba839c934257bafe1b139eb78ed3a480
3
+ metadata.gz: 2e288828c255c06a145d7c88a11c5b0b49c8f80c
4
+ data.tar.gz: d232f755214a1234c110c8bc12921c044c879165
5
5
  SHA512:
6
- metadata.gz: ac4170560d19f57e22c226e080a7fee86bbca9f6e7dcad1a022ee5c693f6ec652f663f866b40ba97dbd0e875f4f40349207e53372d258f33c4b865ac4e94041e
7
- data.tar.gz: 8463bdda383dfb9561a7b467e33d9779b18d655333a3f45bd498ae7f73cdadb1965308e2c933ea5ed8957dc5c27cbbea782eb4ecf0546eed5d5ac80441068911
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(&current_ability.can_read)
68
+ # .select(&current_ability.can_update)
69
+ # .select(&current_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
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  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.3
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-07-21 00:00:00.000000000 Z
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan