query-interface-server 1.1.0 → 1.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d57a80e5621b0143a785eaee533770d097ba18
|
4
|
+
data.tar.gz: 0cf664d6c8635237e1437c012ad4e0d7b5d68e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3aa1949ee5b40aee6b3199ed82f487d00690e6795d54543dbc719393c3c449f8b475423844c209fb8f65125267f7d4e1c65b6a5156cfbb8e5e6f94bc8c786f1
|
7
|
+
data.tar.gz: f52e2f7bfda43824a9c3f57950a1099adf56ed502d4f8815f3ea5d1075d9639f71bcf0be2527fab2d7bfe34a22ab48296d1b92cd190d3b0c7dbefbf4418c99cb
|
@@ -34,6 +34,14 @@ module QueryInterface
|
|
34
34
|
self.transformations << {'transformation' => type, 'parameter' => parameter}
|
35
35
|
end
|
36
36
|
|
37
|
+
def exclude(conditions={})
|
38
|
+
self.copy.tap do |query|
|
39
|
+
conditions.each do |key, value|
|
40
|
+
query.add_transformation("exclude", {"field" => key, "value" => value})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
def filter(conditions={})
|
38
46
|
self.copy.tap do |query|
|
39
47
|
conditions.each do |key, value|
|
@@ -17,6 +17,7 @@ module QueryInterface
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
base.instance_variable_set(:@query_transformations, {
|
20
|
+
exclude: {},
|
20
21
|
filter: {},
|
21
22
|
with: {},
|
22
23
|
order: {},
|
@@ -28,6 +29,7 @@ module QueryInterface
|
|
28
29
|
scope = TransformationScope.new
|
29
30
|
scope.instance_eval(&block)
|
30
31
|
|
32
|
+
@query_transformations[:exclude].merge!(scope.excludes)
|
31
33
|
@query_transformations[:filter].merge!(scope.filters)
|
32
34
|
@query_transformations[:with].merge!(scope.withs)
|
33
35
|
@query_transformations[:order].merge!(scope.orders)
|
@@ -40,14 +42,23 @@ module QueryInterface
|
|
40
42
|
end
|
41
43
|
|
42
44
|
class TransformationScope
|
43
|
-
attr_accessor :filters, :withs, :orders
|
45
|
+
attr_accessor :excludes, :filters, :withs, :orders
|
44
46
|
|
45
47
|
def initialize
|
48
|
+
self.excludes = {}
|
46
49
|
self.filters = {}
|
47
50
|
self.withs = {}
|
48
51
|
self.orders = {}
|
49
52
|
end
|
50
53
|
|
54
|
+
def auto_exclude(*names)
|
55
|
+
names.each do |name|
|
56
|
+
self.excludes[name] = Proc.new do |param|
|
57
|
+
exclude(Sequel.qualify(model.table_name, name) => param)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
51
62
|
def auto_filter(*names)
|
52
63
|
names.each do |name|
|
53
64
|
self.filters[name] = Proc.new do |param|
|
@@ -56,6 +67,10 @@ module QueryInterface
|
|
56
67
|
end
|
57
68
|
end
|
58
69
|
|
70
|
+
def exclude(name, &block)
|
71
|
+
self.excludes[name] = block
|
72
|
+
end
|
73
|
+
|
59
74
|
def filter(name, &block)
|
60
75
|
self.filters[name] = block
|
61
76
|
end
|
@@ -31,7 +31,7 @@ module QueryInterface
|
|
31
31
|
|
32
32
|
def validate(transformation)
|
33
33
|
constraints = {
|
34
|
-
filter: :collection, with: :collection,order: :collection,
|
34
|
+
exclude: :collection, filter: :collection, with: :collection, order: :collection,
|
35
35
|
instance: :collection, context: :instance, map_ids: :collection,
|
36
36
|
paginate: :collection, first: :collection, last: :collection, count: :collection
|
37
37
|
}
|
@@ -53,6 +53,10 @@ module QueryInterface
|
|
53
53
|
Sequel.qualify(self.result.model.table_name, primary_key)
|
54
54
|
end
|
55
55
|
|
56
|
+
def exclude(param)
|
57
|
+
self.result.query_transformation(:exclude, param['field'].to_sym, param['value'])
|
58
|
+
end
|
59
|
+
|
56
60
|
def filter(param)
|
57
61
|
self.result.query_transformation(:filter, param['field'].to_sym, param['value'])
|
58
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query-interface-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Kopecky <andreas.kopecky@radarservices.com>
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-07-
|
13
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|