deep_unrest 0.1.72 → 0.1.73

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: 66699a186572baa00ca20f983f1fe7462ee35e59785c2c73d98a9d4502036890
4
- data.tar.gz: 29406a1d5a62da44de4a744f8cc55c99d74e0d186f5c44459f067ce02e38e302
3
+ metadata.gz: 8dc811b66aacee9eef482287d03e975dc75dbd0844d5b198ff3cff8d3acb4a6d
4
+ data.tar.gz: 3302fe2dfde86ab590d4e430b2a5ced5c3d97bdfcad6fe770aff1201600b6f07
5
5
  SHA512:
6
- metadata.gz: 60c92b8c2f70f1c1e83e28666e01244f1db911c1dd49889f3b38961da959afc71bbd333dddc71fcdf7c07a804d463c9bb91786c5a01742c1524bfbd339f13990
7
- data.tar.gz: 6423c1817958c40e37fa27eac897acf599d43131de15c60e05279502df269e8cdc94e969c56156cb9ab673795d9f234939c398341f84d5058a241901d7c1e7f7
6
+ metadata.gz: e5b98c8dd8a70c97d5858f4f3b2ac8cfc4f106a4109d96302e7a1cb3ae492edaf244934beec3b646975f20e1d13dfbdc8b32b8a85de609f07761b37df2531812
7
+ data.tar.gz: 312a209f70086b73cbf636aeefcb318e49c87b5134bc20987612e49d10fe7dae292be6216624b7b1270cd8b0c5f3253eec138b565dbc582e96b32a899818b8da
@@ -116,27 +116,14 @@ module DeepUnrest
116
116
  paginator = get_paginator(query, parent)
117
117
  resource = item[:resource]
118
118
 
119
- r_metaclass = class << resource; self; end
120
- if r_metaclass.method_defined? :records
121
- r_metaclass.class_eval do
122
- alias_method :records_original, :records
123
- end
124
- end
125
-
126
- # TODO: find a way to do this that doesn't blow out the original :records method
127
- resource.define_singleton_method(:records) { |ctx|
128
- full_scope = if self.respond_to? :records_original
129
- records_original(ctx)
130
- else
131
- super(ctx)
132
- end
133
-
134
- item[:scope].merge(full_scope)
135
- }
119
+ # monkey patch the resource to only show authorized records
120
+ old_records = resource.method(:records)
121
+ resource.define_singleton_method(:records) { |ctx| item[:scope].merge(old_records.call(ctx)) }
136
122
 
137
123
  # transform sort value casing for rails
138
124
  sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
139
125
  serializer = JSONAPI::ResourceSerializer.new(resource)
126
+
140
127
  processor = JSONAPI::Processor.new(resource,
141
128
  :find,
142
129
  filters: query[:filter] || {},
@@ -146,8 +133,12 @@ module DeepUnrest
146
133
  paginator: paginator)
147
134
 
148
135
  jsonapi_result = processor.process
136
+
149
137
  resource_results = format_processor_results(resource, jsonapi_result)
150
138
 
139
+ # un-monkey patch the resource :records method
140
+ resource.define_singleton_method(:records) { |ctx| old_records.call(ctx) }
141
+
151
142
  meta << {
152
143
  addr: [*addr, item[:key], 'meta'],
153
144
  serialized_result: {
@@ -178,15 +169,6 @@ module DeepUnrest
178
169
  included << result
179
170
  recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
180
171
  end
181
- ensure
182
- # un-monkey patch the resource :records method
183
- if r_metaclass.method_defined? :records_original
184
- r_metaclass.class_eval do
185
- alias_method :records, :records_original
186
- end
187
- else
188
- r_metaclass.undef_method :records
189
- end
190
172
  end
191
173
 
192
174
  def self.get_query_type(item)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.72'
4
+ VERSION = '0.1.73'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_unrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.72
4
+ version: 0.1.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley