deep_unrest 0.1.55 → 0.1.56

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: e9439a12cece497a2f6c344216e2f71c443dcfe6e9bc8b29b2a0a6bd88aa280e
4
- data.tar.gz: 13886a9c1f9dcb8384e0c80f1ebf14073bd16403ac6098ab5f463346af8c58b3
3
+ metadata.gz: e13381b727ec0a2812128993e0fd888ac8c5acb03f5f5602d098415f33a84132
4
+ data.tar.gz: bea7cdd18acdb17ba2fa03bfb1ea47695107b588d76959d19cd6e83ff4fda5e1
5
5
  SHA512:
6
- metadata.gz: bad6eb16bc28178c2bcb04b5ea88bb63e9dee5326c9da52f52e5c1ea2b2df045255cf52810d36f409cab0f9832b8f7aaa1ab2165a47a2e641344508aef897b2a
7
- data.tar.gz: 165b21701d238820f826283708940f60bdbb9a10376b8980742565a8cb2e706879e2947380733f22a3b0ed8b0a999d5a76aa536397f27707b92c7cf14a51233c
6
+ metadata.gz: 7f6449677c53c33f1196d42134a7eb7aed6d0bf926fb1d29bf71cbadd8eaa7a8dde901984f5b9bb664052f7a56ecce7678c634079818c7cf716e8f44cf729596
7
+ data.tar.gz: e6451b27a0e51830475f8a9aca4fb3b3502a58debe241ee00d4dfdba760461758c07ae39b7d56286d5382ec5cbe2305a67472d71cc6e228bebdb704706d170ac
@@ -16,7 +16,6 @@ module DeepUnrest
16
16
  addr: resource_addr,
17
17
  key: k.camelize(:lower),
18
18
  uuid: uuid,
19
- current_user: user,
20
19
  query: DeepUnrest.deep_underscore_keys(v) },
21
20
  *create_read_mappings(v[:include], user, [*resource_addr, :include])]
22
21
  end.flatten.compact
@@ -52,18 +51,18 @@ module DeepUnrest
52
51
  query
53
52
  end
54
53
 
55
- def self.recurse_included_queries(item, mappings, parent_context, included, meta, addr)
54
+ def self.recurse_included_queries(ctx, item, mappings, parent_context, included, meta, addr)
56
55
  return unless item[:query].key?(:include)
57
56
 
58
57
  item[:query][:include].each do |_k, v|
59
58
  next_context = parent_context.clone
60
59
  next_context[item[:key].singularize] = item[:record]
61
60
  next_mapping = mappings.find { |m| m[:uuid] == v[:uuid] }.clone
62
- execute_query(next_mapping, mappings, next_context, included, meta, addr, item)
61
+ execute_query(ctx, next_mapping, mappings, next_context, included, meta, addr, item)
63
62
  end
64
63
  end
65
64
 
66
- def self.query_item(mapping, mappings, parent_context, included, meta, addr, _parent)
65
+ def self.query_item(ctx, mapping, mappings, parent_context, included, meta, addr, _parent)
67
66
  query = resolve_conditions(mapping[:query].deep_dup, parent_context)
68
67
 
69
68
  raise DeepUnrest::InvalidQuery unless query[:id] || query[:find]
@@ -88,7 +87,7 @@ module DeepUnrest
88
87
 
89
88
  included << result
90
89
 
91
- recurse_included_queries(result, mappings, parent_context, included, meta, [*next_addr, :include])
90
+ recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
92
91
  end
93
92
 
94
93
  def self.get_paginator(query, _parent)
@@ -103,7 +102,7 @@ module DeepUnrest
103
102
  end
104
103
  end
105
104
 
106
- def self.query_list(item, mappings, parent_context, included, meta, addr, parent)
105
+ def self.query_list(ctx, item, mappings, parent_context, included, meta, addr, parent)
107
106
  base_query = item[:query].deep_dup
108
107
  extension = base_query.dig(:extend, parent&.fetch(:record)&.id&.to_s&.underscore) || {}
109
108
  query = resolve_conditions(base_query.deep_merge(extension),
@@ -120,22 +119,20 @@ module DeepUnrest
120
119
  item[:scope].merge(records_original(ctx))
121
120
  }
122
121
 
123
- begin
124
- # transform sort value casing for rails
125
- sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
126
-
127
- processor = JSONAPI::Processor.new(resource,
128
- :find,
129
- filters: query[:filter] || {},
130
- context: { current_user: item[:current_user] },
131
- sort_criteria: sort_criteria,
132
- paginator: paginator)
133
-
134
- jsonapi_result = processor.process
135
- ensure
136
- # un-monkey patch the resource :records method
137
- r_metaclass.send(:alias_method, :records, :records_original)
138
- end
122
+ # transform sort value casing for rails
123
+ sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
124
+
125
+ processor = JSONAPI::Processor.new(resource,
126
+ :find,
127
+ filters: query[:filter] || {},
128
+ context: ctx,
129
+ sort_criteria: sort_criteria,
130
+ paginator: paginator)
131
+
132
+ jsonapi_result = processor.process
133
+
134
+ # un-monkey patch the resource :records method
135
+ r_metaclass.send(:alias_method, :records, :records_original)
139
136
 
140
137
  meta << {
141
138
  addr: [*addr, item[:key], 'meta'],
@@ -165,7 +162,7 @@ module DeepUnrest
165
162
  }
166
163
 
167
164
  included << result
168
- recurse_included_queries(result, mappings, parent_context, included, meta, [*next_addr, :include])
165
+ recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
169
166
  end
170
167
  end
171
168
 
@@ -175,17 +172,17 @@ module DeepUnrest
175
172
  :list
176
173
  end
177
174
 
178
- def self.execute_query(item, mappings, parent_context, included, meta, addr, parent = nil)
175
+ def self.execute_query(ctx, item, mappings, parent_context, included, meta, addr, parent = nil)
179
176
  if get_query_type(item) == :list
180
- query_list(item, mappings, parent_context, included, meta, addr, parent)
177
+ query_list(ctx, item, mappings, parent_context, included, meta, addr, parent)
181
178
  else
182
- query_item(item, mappings, parent_context, included, meta, addr, parent)
179
+ query_item(ctx, item, mappings, parent_context, included, meta, addr, parent)
183
180
  end
184
181
  end
185
182
 
186
- def self.execute_queries(mappings, parent_context = {}, included = [], meta = [], addr = [])
183
+ def self.execute_queries(ctx, mappings, parent_context = {}, included = [], meta = [], addr = [])
187
184
  mappings.select { |m| m[:addr].size == 1 }.each do |item|
188
- item[:results] = execute_query(item, mappings, parent_context, included, meta, addr)
185
+ item[:results] = execute_query(ctx, item, mappings, parent_context, included, meta, addr)
189
186
  end
190
187
  [included, meta]
191
188
  end
@@ -209,7 +206,7 @@ module DeepUnrest
209
206
  DeepUnrest.collect_authorized_scopes(mappings, user)
210
207
 
211
208
  # read data
212
- data, meta = execute_queries(mappings)
209
+ data, meta = execute_queries(ctx, mappings)
213
210
 
214
211
  # serialize using JSONAPI resource serializers
215
212
  serialize_results(ctx, data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.55'
4
+ VERSION = '0.1.56'
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.55
4
+ version: 0.1.56
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-12-11 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails