deep_unrest 0.1.46 → 0.1.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_unrest/read.rb +12 -5
- data/lib/deep_unrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5eb1f49228c25c6bf01ba850fb3ff14badfeb7b7b40ba3f7175e37f422c6538
|
4
|
+
data.tar.gz: edbb9ec4e3e1626627525305a552bdd5c090c356c6d4623c129196dab1320a34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e85bb3015a45cdc21920cddafc5bfe12981f0d328acb0bb07f127683a6b11d291454d0a32e62377842305300a9e56593b99b66df33cadfa009ea91fef3b7f0e
|
7
|
+
data.tar.gz: 622ad42af8adfaf335ac7341f9fd5446ae6885dce3acd05808e556cd1c186daef58629428141022f6131103a78c099aa057f7e23b7bf78f73375ec063bdd1db0
|
data/lib/deep_unrest/read.rb
CHANGED
@@ -4,6 +4,7 @@ module DeepUnrest
|
|
4
4
|
module Read
|
5
5
|
def self.create_read_mappings(params, addr = [])
|
6
6
|
return unless params
|
7
|
+
|
7
8
|
params.map do |k, v|
|
8
9
|
resource_addr = [*addr, k]
|
9
10
|
uuid = SecureRandom.uuid
|
@@ -36,9 +37,11 @@ module DeepUnrest
|
|
36
37
|
elsif query.is_a? Hash
|
37
38
|
query.each do |k, v|
|
38
39
|
next unless v.is_a? Hash
|
40
|
+
|
39
41
|
if v[:from_context]
|
40
42
|
name, attr = v[:from_context].split('.')
|
41
43
|
next unless parent_context[name]
|
44
|
+
|
42
45
|
query[k] = parent_context[name].send(attr.underscore)
|
43
46
|
else
|
44
47
|
resolve_conditions(v, parent_context)
|
@@ -50,6 +53,7 @@ module DeepUnrest
|
|
50
53
|
|
51
54
|
def self.recurse_included_queries(item, mappings, parent_context, included, meta, addr)
|
52
55
|
return unless item[:query].key?(:include)
|
56
|
+
|
53
57
|
item[:query][:include].each do |_k, v|
|
54
58
|
next_context = parent_context.clone
|
55
59
|
next_context[item[:key].singularize] = item[:record]
|
@@ -61,6 +65,7 @@ module DeepUnrest
|
|
61
65
|
def self.query_item(mapping, mappings, parent_context, included, meta, addr, _parent)
|
62
66
|
query = resolve_conditions(mapping[:query].deep_dup, parent_context)
|
63
67
|
raise DeepUnrest::InvalidQuery unless query[:id] || query[:find]
|
68
|
+
|
64
69
|
record = if query.key?(:id)
|
65
70
|
mapping[:scope].find(query[:id]) if query.key?(:id)
|
66
71
|
else
|
@@ -94,7 +99,7 @@ module DeepUnrest
|
|
94
99
|
|
95
100
|
def self.query_list(item, mappings, parent_context, included, meta, addr, parent)
|
96
101
|
base_query = item[:query].deep_dup
|
97
|
-
extension = base_query.dig(:extend, parent&.fetch(:record)&.id&.to_s) || {}
|
102
|
+
extension = base_query.dig(:extend, parent&.fetch(:record)&.id&.to_s&.underscore) || {}
|
98
103
|
query = resolve_conditions(base_query.deep_merge(extension),
|
99
104
|
parent_context)
|
100
105
|
|
@@ -105,13 +110,13 @@ module DeepUnrest
|
|
105
110
|
r_metaclass = class << resource; self; end
|
106
111
|
r_metaclass.send(:define_method, :records) { |_ctx| item[:scope] }
|
107
112
|
|
108
|
-
# transform sort value casing
|
109
|
-
query[:sort]&.
|
113
|
+
# transform sort value casing for rails
|
114
|
+
sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
|
110
115
|
|
111
116
|
processor = JSONAPI::Processor.new(item[:resource],
|
112
117
|
:find,
|
113
118
|
filters: query[:filter] || {},
|
114
|
-
sort_criteria:
|
119
|
+
sort_criteria: sort_criteria,
|
115
120
|
paginator: paginator)
|
116
121
|
|
117
122
|
jsonapi_result = processor.process
|
@@ -121,6 +126,8 @@ module DeepUnrest
|
|
121
126
|
serialized_result: {
|
122
127
|
paginationParams: jsonapi_result.pagination_params,
|
123
128
|
recordCount: jsonapi_result.record_count,
|
129
|
+
sort: query[:sort],
|
130
|
+
recordCount: jsonapi_result.record_count
|
124
131
|
}
|
125
132
|
}
|
126
133
|
|
@@ -139,6 +146,7 @@ module DeepUnrest
|
|
139
146
|
|
140
147
|
def self.get_query_type(item)
|
141
148
|
return :detail unless plural?(item[:key])
|
149
|
+
|
142
150
|
:list
|
143
151
|
end
|
144
152
|
|
@@ -157,7 +165,6 @@ module DeepUnrest
|
|
157
165
|
[included, meta]
|
158
166
|
end
|
159
167
|
|
160
|
-
|
161
168
|
def self.format_response(mappings)
|
162
169
|
response = {}
|
163
170
|
mappings.each do |mapping|
|
data/lib/deep_unrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_unrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.47
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lynn Hurley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|