Sha256: d5a6435b3c6228828016d78e0837f39ae40993c6db82dce15d261fc93e897ed9
Contents?: true
Size: 1.52 KB
Versions: 26
Compression:
Stored size: 1.52 KB
Contents
module Foobara module BuiltinTypes module Attributes module SupportedTransformers class Defaults < Value::Transformer module TypeDeclarationExtension module ExtendAttributesTypeDeclaration module Desugarizers class MoveDefaultsFromElementTypesToRoot < TypeDeclarations::Desugarizer def applicable?(value) value.is_a?(::Hash) && value[:type] == :attributes end def desugarize(rawish_type_declaration) defaults = rawish_type_declaration[:defaults] defaults = defaults ? defaults.dup : {} element_type_declarations = rawish_type_declaration[:element_type_declarations] element_type_declarations.each_pair do |attribute_name, attribute_type_declaration| if attribute_type_declaration.is_a?(Hash) && attribute_type_declaration.key?(:default) default = attribute_type_declaration[:default] element_type_declarations[attribute_name] = attribute_type_declaration.except(:default) defaults.merge!(attribute_name => default) end end rawish_type_declaration[:defaults] = defaults unless defaults.empty? rawish_type_declaration end end end end end end end end end end
Version data entries
26 entries across 26 versions & 1 rubygems