lib/dry/data/compiler.rb in dry-data-0.2.0 vs lib/dry/data/compiler.rb in dry-data-0.2.1
- old
+ new
@@ -16,24 +16,28 @@
end
def visit_type(node)
type, args = node
- if args
+ if respond_to?(:"visit_#{type}")
send(:"visit_#{type}", args)
else
registry[type]
end
end
+ def visit_sum(node)
+ node.map { |type| visit(type) }.reduce(:|)
+ end
+
def visit_hash(node)
constructor, schema = node
registry['hash'].public_send(constructor, schema.map { |key| visit(key) }.reduce(:merge))
end
def visit_key(node)
name, types = node
- { name => types.map { |id| registry[id] }.reduce(:|) }
+ { name => visit(types) }
end
end
end
end