ocean-rails 2.10.0 → 2.10.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 199cd45800bf7316cb1bb1b79f622ee1c6a74556
4
- data.tar.gz: 8865f5b42851598a6b02ae921e62e42487d6ce9b
3
+ metadata.gz: fbd8005493023e3421fad5e17b6f141bd484f249
4
+ data.tar.gz: 5103477f62b4d283d8d0db84948606a1e1b3d054
5
5
  SHA512:
6
- metadata.gz: 7db74a25a4eeddb2b8ce989ab9725c211a272c4353aeabc4b3099ee55e7f7525a8af5f6b9abcd3f23164b549a1309163ddc829a572c10874c094ed1d0440a27d
7
- data.tar.gz: 415353c47a9a3a8a09e4307262a1952f0dc7fcbf8a909145a1bd566bde5478c9500eea6ad6e43d689a0ed795ea2055376c682211e5b2923065c63a4e06ec7f55
6
+ metadata.gz: 28d40805d7d915875b4cb88834cbc9291c4488633a74f3581648ba4e395afbbd96c7254f7253b6d3883e8a0c3773bce2c93726123fd7b2e6a0ac91dc56af7d55
7
+ data.tar.gz: 07ac89cd9536620bc15441c1ad10d12e5ae70d63f1e3d4239977bab241853e4cc944ae2c2aa6ec02de45ee68c707e3a01c6c9647efb7230186c91da729e07a82
data/lib/ocean-rails.rb CHANGED
@@ -68,10 +68,31 @@ end
68
68
  #
69
69
  def add_right_restrictions(rel, restrictions)
70
70
  return rel unless restrictions
71
- # The below works only for a single restriction (multiple should be ORed)
72
- restrictions.each do |rr|
73
- rel = rel.where("app" => rr["app"]) if rr["app"] != "*"
74
- rel = rel.where("context" => rr["context"]) if rr["context"] != "*"
71
+ # First get the table to use as a basis for the OR clauses
72
+ t = rel.arel_table
73
+ # Accumulating Arel AND clauses
74
+ cond = restrictions.inject([]) do |acc, rr|
75
+ app = rr['app']
76
+ context = rr['context']
77
+ if app != '*' && context != '*'
78
+ acc << t[:app].eq(app).and(t[:context].eq(context))
79
+ elsif app != '*' && context == '*'
80
+ acc << t[:app].eq(app)
81
+ elsif app == '*' && context != '*'
82
+ acc << t[:context].eq(context)
83
+ end
84
+ acc
85
+ end
86
+ # Process the clauses. We might not need to OR anything.
87
+ case cond.length
88
+ when 0
89
+ return rel
90
+ when 1
91
+ return rel.where(cond.first)
92
+ else
93
+ # OR the multiple clauses together
94
+ cond = cond.inject { |a, b| a.or(b) }
95
+ # Return a relation built from the Arel condition we've constructed
96
+ rel.where(cond)
75
97
  end
76
- rel
77
98
  end
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "2.10.0"
2
+ VERSION = "2.10.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-22 00:00:00.000000000 Z
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus