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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daa31821b2ed08b5dcfa8ab650ea11a9a9e60371
4
- data.tar.gz: 1ea3ccdc81754648db6814386089a25e0d10818f
3
+ metadata.gz: 1a9e31bc96fba8e032b7420e7b82b4086c3c240e
4
+ data.tar.gz: c31c119f8dcce46c9e21822ec7b5214af29b2c2b
5
5
  SHA512:
6
- metadata.gz: a6733f538d3256a7ca7888c14e499542b0a4c2c5e95c361a7e2ec7f93709b43fc56a92c0a0cfa7a3b809613e793b75dd635a107caebe5781dc78fa53d309e24c
7
- data.tar.gz: b3020aaaed2ae56ca5065fe73dfbea1b7b18552f0bb36411858190520ccc71555033c88005b81c6cf092067688cd3100546ba06a4d0071b565a4529c51c7c18e
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] = adapter.sideloading_classes[:has_many]
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] = adapter.sideloading_classes[:belongs_to]
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] = adapter.sideloading_classes[:has_one]
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] = adapter.sideloading_classes[:many_to_many]
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
- if _link = link?
42
- if @resource_class.validate_endpoints?
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
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.beta.3"
2
+ VERSION = "1.0.beta.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.beta.3
4
+ version: 1.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond