graphiti 1.0.beta.3 → 1.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti.rb +22 -0
- data/lib/graphiti/resource/sideloading.rb +4 -4
- data/lib/graphiti/util/serializer_relationships.rb +19 -6
- data/lib/graphiti/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a9e31bc96fba8e032b7420e7b82b4086c3c240e
|
4
|
+
data.tar.gz: c31c119f8dcce46c9e21822ec7b5214af29b2c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132831e66a4d1ad626c6b2a1f12947cd6d6f8df125d522eaeefb8ec3b5b1a178bbef4342d84f768d05ed63f633fc152bcdb965b4e3222e78443c7081e7dd4678
|
7
|
+
data.tar.gz: faa9294d0b29267c092c54ae2ebc61943047f45f54a5ec95dabb64bbe703384a18f0aaf51a92cf112bb3ac0c7625be56a023cab89c1229e40f1a555dba79b94d
|
data/lib/graphiti.rb
CHANGED
@@ -143,3 +143,25 @@ module Graphiti
|
|
143
143
|
end
|
144
144
|
|
145
145
|
require "graphiti/runner"
|
146
|
+
|
147
|
+
# Because we set 2 magic variables when processing the graph,
|
148
|
+
# as_json will fail on a PORO with stack level too deep
|
149
|
+
#
|
150
|
+
# #as_json calls #instance_variables, defined in
|
151
|
+
# active_support/core_ext/object/instance_variables.rb
|
152
|
+
#
|
153
|
+
# So, override that to not see these magic vars.
|
154
|
+
module InstanceVariableOverride
|
155
|
+
def instance_values
|
156
|
+
values = super
|
157
|
+
if @__graphiti_serializer
|
158
|
+
values.reject! do |v|
|
159
|
+
['__graphiti_serializer', '__graphiti_resource'].include?(v)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
values
|
163
|
+
end
|
164
|
+
end
|
165
|
+
class Object
|
166
|
+
prepend InstanceVariableOverride
|
167
|
+
end
|
@@ -31,22 +31,22 @@ module Graphiti
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def has_many(name, opts = {}, &blk)
|
34
|
-
opts[:class]
|
34
|
+
opts[:class] ||= adapter.sideloading_classes[:has_many]
|
35
35
|
allow_sideload(name, opts, &blk)
|
36
36
|
end
|
37
37
|
|
38
38
|
def belongs_to(name, opts = {}, &blk)
|
39
|
-
opts[:class]
|
39
|
+
opts[:class] ||= adapter.sideloading_classes[:belongs_to]
|
40
40
|
allow_sideload(name, opts, &blk)
|
41
41
|
end
|
42
42
|
|
43
43
|
def has_one(name, opts = {}, &blk)
|
44
|
-
opts[:class]
|
44
|
+
opts[:class] ||= adapter.sideloading_classes[:has_one]
|
45
45
|
allow_sideload(name, opts, &blk)
|
46
46
|
end
|
47
47
|
|
48
48
|
def many_to_many(name, opts = {}, &blk)
|
49
|
-
opts[:class]
|
49
|
+
opts[:class] ||= adapter.sideloading_classes[:many_to_many]
|
50
50
|
allow_sideload(name, opts, &blk)
|
51
51
|
end
|
52
52
|
|
@@ -38,18 +38,19 @@ module Graphiti
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def block
|
41
|
-
|
42
|
-
|
43
|
-
validate_link! unless @sideload.link_proc
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
41
|
+
_link = link?
|
42
|
+
_resource_class = @resource_class
|
47
43
|
_sl = @sideload
|
48
44
|
_data_proc = data_proc
|
45
|
+
_self = self
|
46
|
+
validate_link! if eagerly_validate_links?
|
47
|
+
|
49
48
|
proc do
|
50
49
|
data { instance_eval(&_data_proc) }
|
51
50
|
|
52
51
|
if _link
|
52
|
+
_self.send(:validate_link!) unless _self.send(:eagerly_validate_links?)
|
53
|
+
|
53
54
|
if @proxy.query.links?
|
54
55
|
link(:related) do
|
55
56
|
::Graphiti::Util::Link.new(_sl, @object).generate
|
@@ -74,7 +75,19 @@ module Graphiti
|
|
74
75
|
}
|
75
76
|
end
|
76
77
|
|
78
|
+
def eagerly_validate_links?
|
79
|
+
if defined?(::Rails)
|
80
|
+
::Rails.application.config.eager_load
|
81
|
+
else
|
82
|
+
true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
77
86
|
def validate_link!
|
87
|
+
return unless link?
|
88
|
+
return unless @resource_class.validate_endpoints?
|
89
|
+
return if @sideload.link_proc
|
90
|
+
|
78
91
|
unless Graphiti.config.context_for_endpoint
|
79
92
|
raise Errors::Unlinkable.new(@resource_class, @sideload)
|
80
93
|
end
|
data/lib/graphiti/version.rb
CHANGED