Skip to content

Commit ae85934

Browse files
committed
Node deref before subscripting, not after. better not to follow refs too eagerly, the caller is less likely to want the deref'd schema in some meta cases.
1 parent a760c44 commit ae85934

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/scorpio/json/node.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ def content
3838
end
3939

4040
def [](k)
41+
node = self
42+
content = node.content
43+
if content.is_a?(Hash) && !content.key?(k)
44+
node = node.deref
45+
content = node.content
46+
end
4147
begin
4248
el = content[k]
4349
rescue TypeError => e
4450
raise(e.class, e.message + "\nsubscripting from #{content.inspect} (#{content.class}): #{k.inspect} (#{k.class})", e.backtrace)
4551
end
4652
if el.is_a?(Hash) || el.is_a?(Array)
47-
self.class.new_by_type(document, path + [k]).deref
53+
self.class.new_by_type(node.document, node.path + [k])
4854
else
4955
el
5056
end

0 commit comments

Comments
 (0)