graphiti 1.0.alpha.7 → 1.0.alpha.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti/renderer.rb +15 -6
- data/lib/graphiti/resource.rb +1 -1
- data/lib/graphiti/resource/configuration.rb +4 -0
- data/lib/graphiti/util/attribute_check.rb +12 -1
- 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: 68063fcedb7deeeb604ebb6c88e58fe525867ee8
|
4
|
+
data.tar.gz: cb720f2dcada7d2b92332e8b734ff9fcdc879c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bba382cda2e598726ab189f9b38e256fce145cbe911c9342d706811930da89ae76947f011ff86dacb3e7265b1da305e7074e9471eb7e7d9bbf45ee1ac24484f
|
7
|
+
data.tar.gz: aa1ab4574c5bb2a51fb0c76d251c0061e44af47287e7906121d566697fa9eb8a8f4cddf65d9dfe7bd2c33f402761a9b2911f4ac37925175cfe55233535f4b1bb
|
data/lib/graphiti/renderer.rb
CHANGED
@@ -14,22 +14,31 @@ module Graphiti
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_jsonapi
|
17
|
-
render(
|
17
|
+
render(self.class.jsonapi_renderer).to_json
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_json
|
21
|
-
render(
|
21
|
+
render(self.class.hash_renderer(@proxy)).to_json
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_xml
|
25
|
-
render(
|
25
|
+
render(self.class.hash_renderer(@proxy)).to_xml(root: :data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.jsonapi_renderer
|
29
|
+
@jsonapi_renderer ||= JSONAPI::Serializable::Renderer
|
30
|
+
.new(JSONAPI::Renderer.new)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.hash_renderer(proxy)
|
34
|
+
implementation = Graphiti::HashRenderer.new(proxy.resource)
|
35
|
+
JSONAPI::Serializable::Renderer.new(implementation)
|
26
36
|
end
|
27
37
|
|
28
38
|
private
|
29
39
|
|
30
|
-
def render(
|
40
|
+
def render(renderer)
|
31
41
|
notify do
|
32
|
-
instance = JSONAPI::Serializable::Renderer.new(implementation)
|
33
42
|
options[:fields] = proxy.fields
|
34
43
|
options[:expose] ||= {}
|
35
44
|
options[:expose][:extra_fields] = proxy.extra_fields
|
@@ -37,7 +46,7 @@ module Graphiti
|
|
37
46
|
options[:include] = proxy.include_hash
|
38
47
|
options[:meta] ||= {}
|
39
48
|
options[:meta].merge!(stats: proxy.stats) unless proxy.stats.empty?
|
40
|
-
|
49
|
+
renderer.render(records, options)
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
data/lib/graphiti/resource.rb
CHANGED
@@ -56,6 +56,10 @@ module Graphiti
|
|
56
56
|
attribute[flag] != :required
|
57
57
|
end
|
58
58
|
|
59
|
+
def cache?
|
60
|
+
!!@cache
|
61
|
+
end
|
62
|
+
|
59
63
|
def error_class
|
60
64
|
Errors::AttributeError
|
61
65
|
end
|
@@ -64,8 +68,15 @@ module Graphiti
|
|
64
68
|
attribute[flag] != false
|
65
69
|
end
|
66
70
|
|
71
|
+
# If running in a request context, we've already loaded everything
|
72
|
+
# and there's no reason to perform logic, so go through attriubte cache
|
73
|
+
# Otherwise, this is a performance hit during typecasting
|
67
74
|
def attribute
|
68
|
-
|
75
|
+
@attribute ||= if request?
|
76
|
+
resource.class.attribute_cache[name]
|
77
|
+
else
|
78
|
+
resource.all_attributes[name]
|
79
|
+
end
|
69
80
|
end
|
70
81
|
|
71
82
|
def attribute?
|
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.8
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|