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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e415f7ba0062481c879d60a64e3f7bd7796f641d0be61d5288783d4f51bee215
4
- data.tar.gz: d0b5e839fa072dec11ad4c44ae977346cf207c5d22f4072ab7160066442a9c57
3
+ metadata.gz: b5eb1f49228c25c6bf01ba850fb3ff14badfeb7b7b40ba3f7175e37f422c6538
4
+ data.tar.gz: edbb9ec4e3e1626627525305a552bdd5c090c356c6d4623c129196dab1320a34
5
5
  SHA512:
6
- metadata.gz: 907b11f20a169e6607ae3a49cf0bbc6dfc440d8b08f7858a4836825c5097a9c424cb53665a2eacd735ca7824d4b399eb2b26da6ba0893e33100ef97ee55a5336
7
- data.tar.gz: d1d989d75bb822f366501f13be9e509eda2a954eb3521a493a68d805d568c0c0ebb724d2cbd17ab839bb21b23b7c1398c6db1d4614c8ab90aab19b3648b06859
6
+ metadata.gz: 0e85bb3015a45cdc21920cddafc5bfe12981f0d328acb0bb07f127683a6b11d291454d0a32e62377842305300a9e56593b99b66df33cadfa009ea91fef3b7f0e
7
+ data.tar.gz: 622ad42af8adfaf335ac7341f9fd5446ae6885dce3acd05808e556cd1c186daef58629428141022f6131103a78c099aa057f7e23b7bf78f73375ec063bdd1db0
@@ -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]&.each { |s| s[:field] = s[:field].underscore }
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: query[:sort],
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.46'
4
+ VERSION = '0.1.47'
5
5
  end
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.46
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-03 00:00:00.000000000 Z
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails