class Dry::Data::Compiler

Attributes

registry[R]

Public Class Methods

new(registry) click to toggle source
# File lib/dry/data/compiler.rb, line 6
def initialize(registry)
  @registry = registry
end

Public Instance Methods

call(ast) click to toggle source
# File lib/dry/data/compiler.rb, line 10
def call(ast)
  visit(ast)
end
visit(node, *args) click to toggle source
# File lib/dry/data/compiler.rb, line 14
def visit(node, *args)
  send(:"visit_#{node[0]}", node[1], *args)
end
visit_array(node) click to toggle source
# File lib/dry/data/compiler.rb, line 33
def visit_array(node)
  registry['array'].member(call(node))
end
visit_form_array(node) click to toggle source
# File lib/dry/data/compiler.rb, line 37
def visit_form_array(node)
  registry['form.array'].member(call(node))
end
visit_form_hash(node) click to toggle source
# File lib/dry/data/compiler.rb, line 46
def visit_form_hash(node)
  constructor, schema = node
  registry['form.hash'].public_send(constructor, schema.map { |key| visit(key) }.reduce(:merge))
end
visit_hash(node) click to toggle source
# File lib/dry/data/compiler.rb, line 41
def visit_hash(node)
  constructor, schema = node
  registry['hash'].public_send(constructor, schema.map { |key| visit(key) }.reduce(:merge))
end
visit_key(node) click to toggle source
# File lib/dry/data/compiler.rb, line 51
def visit_key(node)
  name, types = node
  { name => visit(types) }
end
visit_sum(node) click to toggle source
# File lib/dry/data/compiler.rb, line 29
def visit_sum(node)
  node.map { |type| visit(type) }.reduce(:|)
end
visit_type(node) click to toggle source
# File lib/dry/data/compiler.rb, line 18
def visit_type(node)
  type, args = node
  meth = :"visit_#{type.gsub('.', '_')}"

  if respond_to?(meth)
    send(meth, args)
  else
    registry[type]
  end
end