jsonapi-resources 0.10.7 → 0.11.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +39 -2
- data/lib/generators/jsonapi/controller_generator.rb +2 -0
- data/lib/generators/jsonapi/resource_generator.rb +2 -0
- data/lib/jsonapi/active_relation/adapters/join_left_active_record_adapter.rb +3 -2
- data/lib/jsonapi/active_relation/join_manager.rb +30 -18
- data/lib/jsonapi/active_relation/join_manager_v10.rb +305 -0
- data/lib/jsonapi/active_relation_retrieval.rb +885 -0
- data/lib/jsonapi/active_relation_retrieval_v09.rb +715 -0
- data/lib/jsonapi/{active_relation_resource.rb → active_relation_retrieval_v10.rb} +113 -135
- data/lib/jsonapi/acts_as_resource_controller.rb +49 -49
- data/lib/jsonapi/cached_response_fragment.rb +4 -2
- data/lib/jsonapi/callbacks.rb +2 -0
- data/lib/jsonapi/compiled_json.rb +2 -0
- data/lib/jsonapi/configuration.rb +35 -15
- data/lib/jsonapi/error.rb +2 -0
- data/lib/jsonapi/error_codes.rb +2 -0
- data/lib/jsonapi/exceptions.rb +2 -0
- data/lib/jsonapi/formatter.rb +2 -0
- data/lib/jsonapi/include_directives.rb +77 -19
- data/lib/jsonapi/link_builder.rb +2 -0
- data/lib/jsonapi/mime_types.rb +6 -10
- data/lib/jsonapi/naive_cache.rb +2 -0
- data/lib/jsonapi/operation.rb +2 -0
- data/lib/jsonapi/operation_result.rb +2 -0
- data/lib/jsonapi/paginator.rb +2 -17
- data/lib/jsonapi/path.rb +2 -0
- data/lib/jsonapi/path_segment.rb +4 -2
- data/lib/jsonapi/processor.rb +100 -153
- data/lib/jsonapi/relationship.rb +89 -35
- data/lib/jsonapi/{request_parser.rb → request.rb} +157 -164
- data/lib/jsonapi/resource.rb +7 -2
- data/lib/jsonapi/{basic_resource.rb → resource_common.rb} +187 -88
- data/lib/jsonapi/resource_controller.rb +2 -0
- data/lib/jsonapi/resource_controller_metal.rb +2 -0
- data/lib/jsonapi/resource_fragment.rb +17 -15
- data/lib/jsonapi/resource_identity.rb +6 -0
- data/lib/jsonapi/resource_serializer.rb +20 -4
- data/lib/jsonapi/resource_set.rb +36 -16
- data/lib/jsonapi/resource_tree.rb +191 -0
- data/lib/jsonapi/resources/railtie.rb +3 -1
- data/lib/jsonapi/resources/version.rb +3 -1
- data/lib/jsonapi/response_document.rb +4 -2
- data/lib/jsonapi/routing_ext.rb +4 -2
- data/lib/jsonapi/simple_resource.rb +13 -0
- data/lib/jsonapi-resources.rb +10 -4
- data/lib/tasks/check_upgrade.rake +3 -1
- metadata +47 -15
- data/lib/jsonapi/resource_id_tree.rb +0 -112
@@ -1,112 +0,0 @@
|
|
1
|
-
module JSONAPI
|
2
|
-
|
3
|
-
# A tree structure representing the resource structure of the requested resource(s). This is an intermediate structure
|
4
|
-
# used to keep track of the resources, by identity, found at different included relationships. It will be flattened and
|
5
|
-
# the resource instances will be fetched from the cache or the record store.
|
6
|
-
class ResourceIdTree
|
7
|
-
|
8
|
-
attr_reader :fragments, :related_resource_id_trees
|
9
|
-
|
10
|
-
# Gets the related Resource Id Tree for a relationship, and creates it first if it does not exist
|
11
|
-
#
|
12
|
-
# @param relationship [JSONAPI::Relationship]
|
13
|
-
#
|
14
|
-
# @return [JSONAPI::RelatedResourceIdTree] the new or existing resource id tree for the requested relationship
|
15
|
-
def fetch_related_resource_id_tree(relationship)
|
16
|
-
relationship_name = relationship.name.to_sym
|
17
|
-
@related_resource_id_trees[relationship_name] ||= RelatedResourceIdTree.new(relationship, self)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def init_included_relationships(fragment, include_related)
|
23
|
-
include_related && include_related.each_key do |relationship_name|
|
24
|
-
fragment.initialize_related(relationship_name)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class PrimaryResourceIdTree < ResourceIdTree
|
30
|
-
|
31
|
-
# Creates a PrimaryResourceIdTree with no resources and no related ResourceIdTrees
|
32
|
-
def initialize
|
33
|
-
@fragments ||= {}
|
34
|
-
@related_resource_id_trees ||= {}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Adds each Resource Fragment to the Resources hash
|
38
|
-
#
|
39
|
-
# @param fragments [Hash]
|
40
|
-
# @param include_related [Hash]
|
41
|
-
#
|
42
|
-
# @return [null]
|
43
|
-
def add_resource_fragments(fragments, include_related)
|
44
|
-
fragments.each_value do |fragment|
|
45
|
-
add_resource_fragment(fragment, include_related)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Adds a Resource Fragment to the Resources hash
|
50
|
-
#
|
51
|
-
# @param fragment [JSONAPI::ResourceFragment]
|
52
|
-
# @param include_related [Hash]
|
53
|
-
#
|
54
|
-
# @return [null]
|
55
|
-
def add_resource_fragment(fragment, include_related)
|
56
|
-
fragment.primary = true
|
57
|
-
|
58
|
-
init_included_relationships(fragment, include_related)
|
59
|
-
|
60
|
-
@fragments[fragment.identity] = fragment
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class RelatedResourceIdTree < ResourceIdTree
|
65
|
-
|
66
|
-
attr_reader :parent_relationship, :source_resource_id_tree
|
67
|
-
|
68
|
-
# Creates a RelatedResourceIdTree with no resources and no related ResourceIdTrees. A connection to the parent
|
69
|
-
# ResourceIdTree is maintained.
|
70
|
-
#
|
71
|
-
# @param parent_relationship [JSONAPI::Relationship]
|
72
|
-
# @param source_resource_id_tree [JSONAPI::ResourceIdTree]
|
73
|
-
#
|
74
|
-
# @return [JSONAPI::RelatedResourceIdTree] the new or existing resource id tree for the requested relationship
|
75
|
-
def initialize(parent_relationship, source_resource_id_tree)
|
76
|
-
@fragments ||= {}
|
77
|
-
@related_resource_id_trees ||= {}
|
78
|
-
|
79
|
-
@parent_relationship = parent_relationship
|
80
|
-
@parent_relationship_name = parent_relationship.name.to_sym
|
81
|
-
@source_resource_id_tree = source_resource_id_tree
|
82
|
-
end
|
83
|
-
|
84
|
-
# Adds each Resource Fragment to the Resources hash
|
85
|
-
#
|
86
|
-
# @param fragments [Hash]
|
87
|
-
# @param include_related [Hash]
|
88
|
-
#
|
89
|
-
# @return [null]
|
90
|
-
def add_resource_fragments(fragments, include_related)
|
91
|
-
fragments.each_value do |fragment|
|
92
|
-
add_resource_fragment(fragment, include_related)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Adds a Resource Fragment to the fragments hash
|
97
|
-
#
|
98
|
-
# @param fragment [JSONAPI::ResourceFragment]
|
99
|
-
# @param include_related [Hash]
|
100
|
-
#
|
101
|
-
# @return [null]
|
102
|
-
def add_resource_fragment(fragment, include_related)
|
103
|
-
init_included_relationships(fragment, include_related)
|
104
|
-
|
105
|
-
fragment.related_from.each do |rid|
|
106
|
-
@source_resource_id_tree.fragments[rid].add_related_identity(parent_relationship.name, fragment.identity)
|
107
|
-
end
|
108
|
-
|
109
|
-
@fragments[fragment.identity] = fragment
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|