module RiceBubble class Attributes class Object < Base attr_reader :children def initialize(children = {}, &) super(&) @children = Attributes.new( children.transform_values(&method(:instantiate)) ) end def valid?(value) children.all? do |name, attr| attr.valid?(value[name]) end end def validate!(value, path:, **) children.each do |name, attr| child = attr.fetch(value, name) coerced = attr.coerce(child) attr.validate!(child, coerced:, path: "#{path}.#{name}") end end def coerce(value) children.map { |name, attr| attr.coerce(attr.fetch(value, name)) } end end end end