deep_unrest 0.1.72 → 0.1.76

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: 5414c5023858644639737c10519236d5d27d7d5f645a65c1a47f784b5c0f1cdc
4
+ data.tar.gz: e36e32772f0e662881f2d29acbbff47634d6f8cb2f214394a52aa72937a43262
5
5
  SHA512:
6
- metadata.gz: 60c92b8c2f70f1c1e83e28666e01244f1db911c1dd49889f3b38961da959afc71bbd333dddc71fcdf7c07a804d463c9bb91786c5a01742c1524bfbd339f13990
7
- data.tar.gz: 6423c1817958c40e37fa27eac897acf599d43131de15c60e05279502df269e8cdc94e969c56156cb9ab673795d9f234939c398341f84d5058a241901d7c1e7f7
6
+ metadata.gz: afd8b1351ecfc59ae5c4ce9834cdabe02ad3fd4cf89b9e9c955b92512d2a12ca7f1b0a779b649cdc3cc538a8711d8e8071d5199a383ac7f9e11806c9add4e4fe
7
+ data.tar.gz: 5cc341b7eb963ad418a813087c44a24d28aef45548babc7bd35f1f150fba14dc6b804fd501cfc533c950ae7d143224de0422546414241751880b68bc542e8968
@@ -0,0 +1,13 @@
1
+ module DeepUnrest
2
+ module Concerns
3
+ module ResourceScope
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ def records_base(opts)
8
+ opts[:scope] || super(opts)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,6 +4,7 @@ require 'deep_unrest/authorization/pundit_strategy'
4
4
  require 'deep_unrest/paginators/basic'
5
5
  require 'deep_unrest/concerns/null_concern'
6
6
  require 'deep_unrest/concerns/map_temp_ids'
7
+ require 'deep_unrest/concerns/resource_scope'
7
8
 
8
9
  module DeepUnrest
9
10
  class Engine < ::Rails::Engine
@@ -116,36 +116,22 @@ 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
+ resource_scope = item[:scope]
136
120
 
137
121
  # transform sort value casing for rails
138
122
  sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
139
123
  serializer = JSONAPI::ResourceSerializer.new(resource)
124
+
140
125
  processor = JSONAPI::Processor.new(resource,
141
126
  :find,
142
127
  filters: query[:filter] || {},
143
- context: ctx,
128
+ context: ctx.clone.merge(scope: resource_scope),
144
129
  sort_criteria: sort_criteria,
145
130
  serializer: serializer,
146
131
  paginator: paginator)
147
132
 
148
133
  jsonapi_result = processor.process
134
+
149
135
  resource_results = format_processor_results(resource, jsonapi_result)
150
136
 
151
137
  meta << {
@@ -178,15 +164,6 @@ module DeepUnrest
178
164
  included << result
179
165
  recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
180
166
  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
167
  end
191
168
 
192
169
  def self.get_query_type(item)
@@ -239,3 +216,4 @@ module DeepUnrest
239
216
  end
240
217
  end
241
218
  end
219
+
@@ -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.76'
5
5
  end
@@ -110,7 +110,7 @@ module DeepUnrest
110
110
  update_body[:_destroy] = true if item.dig(:query, :destroy)
111
111
  DeepUnrest.set_attr(memo, item[:ar_addr].clone, update_body)
112
112
  if item[:ar_addr].size == 1
113
- item[:mutate] = memo.fetch(*item[:ar_addr])
113
+ item[:mutate] = update_body
114
114
  item[:scope_type] = :update if item[:scope_type] == :show
115
115
  end
116
116
  end
@@ -142,9 +142,10 @@ module DeepUnrest
142
142
  when :destroy
143
143
  id = item.dig(:query, :id)
144
144
  model = item[:klass].find(id)
145
+ model.deep_unrest_query_uuid = item.dig(:query, :uuid)
145
146
  resource = item[:resource].new(model, context)
146
147
  resource.run_callbacks :remove do
147
- item[:klass].destroy(id)
148
+ model.destroy!
148
149
  end
149
150
  end
150
151
 
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.72
4
+ version: 0.1.76
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -147,6 +147,7 @@ files:
147
147
  - lib/deep_unrest/authorization/pundit_strategy.rb
148
148
  - lib/deep_unrest/concerns/map_temp_ids.rb
149
149
  - lib/deep_unrest/concerns/null_concern.rb
150
+ - lib/deep_unrest/concerns/resource_scope.rb
150
151
  - lib/deep_unrest/engine.rb
151
152
  - lib/deep_unrest/paginators/basic.rb
152
153
  - lib/deep_unrest/read.rb