graphiti 1.0.alpha.9 → 1.0.alpha.10
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/lib/graphiti/configuration.rb +2 -0
- data/lib/graphiti/jsonapi_serializable_ext.rb +0 -19
- data/lib/graphiti/resource.rb +5 -3
- data/lib/graphiti/util/serializer_attributes.rb +12 -2
- data/lib/graphiti/util/serializer_relationships.rb +25 -6
- data/lib/graphiti/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d73c18bd56aa9ce3103c3e1be9d6aa53df14d246
|
4
|
+
data.tar.gz: da7f2ff960fb4592610dfb6ea30a5ff981378bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69a8290f78ca0abcee5971e6ffec58c3884d9f81a44f5b2bb59967cfb18311cb9274ad3329689b31c338586347fa2089df0d82e136d1d74a91c2073d591062a3
|
7
|
+
data.tar.gz: ac000566edc5afc1c05af3db4a179454a9766da798995b3c35fcdda9bc01bbff40d697b598c217b39619378a8052f56c7961e931c44ced3663361e9950409503
|
@@ -12,6 +12,7 @@ module Graphiti
|
|
12
12
|
attr_accessor :context_for_endpoint
|
13
13
|
attr_accessor :schema_path
|
14
14
|
attr_accessor :links_on_demand
|
15
|
+
attr_accessor :typecast_reads
|
15
16
|
|
16
17
|
# Set defaults
|
17
18
|
# @api private
|
@@ -20,6 +21,7 @@ module Graphiti
|
|
20
21
|
@concurrency = false
|
21
22
|
@respond_to = [:json, :jsonapi, :xml]
|
22
23
|
@links_on_demand = false
|
24
|
+
@typecast_reads = true
|
23
25
|
|
24
26
|
if defined?(::Rails)
|
25
27
|
@schema_path = "#{::Rails.root}/public/schema.json"
|
@@ -35,25 +35,6 @@ module Graphiti
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
# Temporary fix until fixed upstream
|
39
|
-
# https://github.com/jsonapi-rb/jsonapi-serializable/pull/102
|
40
|
-
module ResourceOverrides
|
41
|
-
def requested_relationships(fields)
|
42
|
-
@_relationships
|
43
|
-
end
|
44
|
-
|
45
|
-
# Allow access to resource methods
|
46
|
-
def method_missing(id, *args, &blk)
|
47
|
-
if @resource.respond_to?(id, true)
|
48
|
-
@resource.send(id, *args, &blk)
|
49
|
-
else
|
50
|
-
super
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
JSONAPI::Serializable::Resource
|
56
|
-
.send(:prepend, ResourceOverrides)
|
57
38
|
JSONAPI::Serializable::Relationship
|
58
39
|
.send(:prepend, RelationshipOverrides)
|
59
40
|
JSONAPI::Serializable::Renderer
|
data/lib/graphiti/resource.rb
CHANGED
@@ -25,9 +25,11 @@ module Graphiti
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def decorate_record(record)
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
unless record.instance_variable_get(:@__graphiti_serializer)
|
29
|
+
serializer = serializer_for(record)
|
30
|
+
record.instance_variable_set(:@__graphiti_serializer, serializer)
|
31
|
+
record.instance_variable_set(:@__graphiti_resource, self)
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
35
|
def with_context(object, namespace = nil)
|
@@ -75,7 +75,12 @@ module Graphiti
|
|
75
75
|
_resource = @resource.new
|
76
76
|
_typecast = typecast(Graphiti::Types[@attr[:type]][:read])
|
77
77
|
->(_) {
|
78
|
-
|
78
|
+
val = @object.send(_name)
|
79
|
+
if Graphiti.config.typecast_reads
|
80
|
+
_typecast.call(val)
|
81
|
+
else
|
82
|
+
val
|
83
|
+
end
|
79
84
|
}
|
80
85
|
end
|
81
86
|
|
@@ -84,7 +89,12 @@ module Graphiti
|
|
84
89
|
_name = @name
|
85
90
|
_typecast = typecast(Graphiti::Types[@attr[:type]][:read])
|
86
91
|
->(serializer_instance = nil) {
|
87
|
-
|
92
|
+
val = serializer_instance.instance_eval(&inner)
|
93
|
+
if Graphiti.config.typecast_reads
|
94
|
+
_typecast.call(val)
|
95
|
+
else
|
96
|
+
val
|
97
|
+
end
|
88
98
|
}
|
89
99
|
end
|
90
100
|
|
@@ -38,21 +38,40 @@ module Graphiti
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def block
|
41
|
-
if link?
|
41
|
+
if _link = link?
|
42
42
|
validate_link! unless @sideload.link_proc
|
43
|
-
|
44
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
_sl = @sideload
|
46
|
+
_data_proc = data_proc
|
47
|
+
proc do
|
48
|
+
data { instance_eval(&_data_proc) }
|
49
|
+
|
50
|
+
if _link
|
45
51
|
if @proxy.query.links?
|
46
52
|
link(:related) do
|
47
|
-
::Graphiti::Util::Link.new(
|
53
|
+
::Graphiti::Util::Link.new(_sl, @object).generate
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
51
|
-
else
|
52
|
-
proc { }
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
def data_proc
|
61
|
+
_sl = @sideload
|
62
|
+
->(_) {
|
63
|
+
if records = @object.public_send(_sl.name)
|
64
|
+
if records.respond_to?(:to_ary)
|
65
|
+
records.each { |r| _sl.resource.decorate_record(r) }
|
66
|
+
else
|
67
|
+
_sl.resource.decorate_record(records)
|
68
|
+
end
|
69
|
+
|
70
|
+
records
|
71
|
+
end
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
56
75
|
def validate_link!
|
57
76
|
unless Graphiti.config.context_for_endpoint
|
58
77
|
raise Errors::Unlinkable.new(@resource_class, @sideload)
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.alpha.
|
4
|
+
version: 1.0.alpha.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|