mongoid_ability 0.3.3 → 0.3.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: 8e46cdf87be76c61f854d456116226b64bd95834
4
- data.tar.gz: ae4c2ebfbe8da92a62a89af5be4428d2679a678b
3
+ metadata.gz: c507aee422f260d41b3362fdaab309fcaaec4b6d
4
+ data.tar.gz: 64cfd77de7d1498dde919e10e3639c7d8be4d668
5
5
  SHA512:
6
- metadata.gz: 86b7fec05cee106cbdbcef83f7e8f9b5a235ccaded227dd019860a18bf072f99ebe783ec0cf3f146bc78e1dd1f91c4b6a74ae54072d22b55daceeaaf4af34c31
7
- data.tar.gz: 837eea204af7eaab2077d5d13a6c1b204f42a3db60ddf1730e81496e522f823c57b861f79fcefc138d43a425c5e18d434c64e3bb709057d125f9d128551e17b6
6
+ metadata.gz: 719e74564b155969eb8873e216e52c85756b82ccbc04573dda5b4ea66c80138c7e1596325daa51dfc15495b3e528db1602ad3c89eea5485170d45cb8bb5df27c
7
+ data.tar.gz: bebec4577d5ef119322b2c9ac30b83a42cd4dc73fd62b0faabd95e686c212741420f0e19eaf964991008c7aba39488534f47bf8ec573e7d22f390e287f6a09fc
@@ -7,24 +7,34 @@ module MongoidAbility
7
7
  # =====================================================================
8
8
 
9
9
  def call
10
- or_conditions = [closed_types_condition, open_ids_condition].reject(&:blank?)
11
- base_class.criteria.where(:$and => [{ :$or => or_conditions }, closed_ids_condition])
10
+ return base_class.criteria unless and_conditions.present?
11
+ base_class.criteria.where(and_conditions)
12
12
  end
13
13
 
14
14
  private # =============================================================
15
15
 
16
+ def or_conditions
17
+ return unless conditions = [closed_types_condition, open_ids_condition].compact.presence
18
+ { :$or => conditions }
19
+ end
20
+
21
+ def and_conditions
22
+ return unless conditions = [or_conditions, closed_ids_condition].compact.presence
23
+ { :$and => conditions }
24
+ end
25
+
16
26
  def closed_types_condition
27
+ return unless values.closed_types.present?
17
28
  { :_type.nin => values.closed_types }
18
29
  end
19
30
 
20
31
  def open_ids_condition
21
- {
22
- :_type.in => values.open_types_and_ids.map(&:type),
23
- :_id.in => values.open_types_and_ids.map(&:id)
24
- }
32
+ return unless values.open_types_and_ids.present?
33
+ { :_id.in => values.open_types_and_ids.map(&:id) }
25
34
  end
26
35
 
27
36
  def closed_ids_condition
37
+ return unless values.closed_ids.present?
28
38
  { :_id.nin => values.closed_ids }
29
39
  end
30
40
 
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
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.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan