jpie 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/json_api/controllers/concerns/resource_actions/preloading.rb +4 -4
- data/lib/json_api/controllers/concerns/resource_actions/resource_loading.rb +15 -3
- data/lib/json_api/controllers/concerns/resource_actions.rb +1 -1
- data/lib/json_api/resources/concerns/model_class_helpers.rb +4 -0
- data/lib/json_api/serialization/concerns/includes_serialization.rb +14 -2
- data/lib/json_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 654010b56dc91dbc6edffc3c54891d7d6cb7eab738f685cbbe0e793aa9d26b13
|
|
4
|
+
data.tar.gz: d400665267796d760e1051697a46bb067c414142be5372e1abb2ac1254e8aaa7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4081700e8daa2cd9e4b209d7cf2d1d0464b44d3678fb9095adc995fe5e075ad5fa00b64af8bc7bdb9a53177f64ba74e999e85f61d56c9c82d2908bede76b579
|
|
7
|
+
data.tar.gz: 6c786599fbfda71820206e62c17dbbb9ed86d28858ae905293b20a9426e3cf64da76dba69c8ffaa7dfff5193f4e42ba203a09ba635943f8ac6212cea95bdfada
|
data/Gemfile.lock
CHANGED
|
@@ -49,15 +49,15 @@ module JSONAPI
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def preload_collection(includes)
|
|
52
|
-
return
|
|
52
|
+
return resource_class.records if includes.empty?
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
resource_class.records.includes(includes)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def preload_single(includes)
|
|
58
|
-
return
|
|
58
|
+
return resource_class.records.find(params[:id]) if includes.empty?
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
resource_class.records.includes(includes).find(params[:id])
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -10,15 +10,27 @@ module JSONAPI
|
|
|
10
10
|
def load_jsonapi_resource
|
|
11
11
|
@resource_name = params[:resource_type]&.singularize
|
|
12
12
|
@jsonapi_namespace = params[:jsonapi_namespace].presence
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@resource = @model_class.find(params[:id]) if params[:id] && @model_class
|
|
13
|
+
load_resource_and_model_class
|
|
14
|
+
load_resource_record
|
|
16
15
|
rescue JSONAPI::ResourceLoader::MissingResourceClass
|
|
17
16
|
@resource_class = nil
|
|
18
17
|
rescue ActiveRecord::RecordNotFound
|
|
19
18
|
render_record_not_found
|
|
20
19
|
end
|
|
21
20
|
|
|
21
|
+
def load_resource_and_model_class
|
|
22
|
+
return unless @resource_name
|
|
23
|
+
|
|
24
|
+
@resource_class = JSONAPI::ResourceLoader.find(@resource_name, namespace: @jsonapi_namespace)
|
|
25
|
+
@model_class = @resource_class.model_class if @resource_class
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def load_resource_record
|
|
29
|
+
return unless params[:id] && @resource_class
|
|
30
|
+
|
|
31
|
+
@resource = @resource_class.records.find(params[:id])
|
|
32
|
+
end
|
|
33
|
+
|
|
22
34
|
def render_record_not_found
|
|
23
35
|
render_jsonapi_error(
|
|
24
36
|
status: 404,
|
|
@@ -34,7 +34,7 @@ module JSONAPI
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def index
|
|
37
|
-
scope = apply_authorization_scope(@preloaded_resources ||
|
|
37
|
+
scope = apply_authorization_scope(@preloaded_resources || resource_class.records, action: :index)
|
|
38
38
|
query = build_query(scope)
|
|
39
39
|
@total_count = query.total_count
|
|
40
40
|
@pagination_applied = query.pagination_applied
|
|
@@ -46,8 +46,20 @@ module JSONAPI
|
|
|
46
46
|
return get_active_storage_records(current_record, association_name)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
get_association_records(current_record, association_name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_association_records(current_record, association_name)
|
|
53
|
+
association = current_record.association(association_name)
|
|
54
|
+
related_klass = association.klass
|
|
55
|
+
return [] if related_klass.blank?
|
|
56
|
+
|
|
57
|
+
build_scoped_relation(related_klass, association).to_a
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def build_scoped_relation(related_klass, association)
|
|
61
|
+
related_base_scope = ResourceLoader.find_for_model(related_klass).records
|
|
62
|
+
related_base_scope.merge(association.scope)
|
|
51
63
|
end
|
|
52
64
|
|
|
53
65
|
def get_active_storage_records(current_record, association_name)
|
data/lib/json_api/version.rb
CHANGED