Sha256: e4db02ad90246c8efc498f0ca33edb72f11e8095de9beed1e71a716db333ea46
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
require "formalist/element/attributes" require "formalist/element/class_interface" module Formalist class Element extend ClassInterface # @api private attr_reader :name, :attributes, :children, :input, :errors # @api private def self.build(**args) new(**args) end # @api private def self.fill(input: {}, errors: {}, **args) new(**args).fill(input: input, errors: errors) end # @api private def initialize(name: nil, attributes: {}, children: [], input: nil, errors: []) @name = name&.to_sym @attributes = self.class.attributes_schema.each_with_object({}) { |(name, defn), hsh| value = attributes.fetch(name) { defn[:default] } hsh[name] = value unless value.nil? } @children = children @input = input @errors = errors end def fill(input: {}, errors: {}, **args) return self if input == @input && errors == @errors args = { name: @name, attributes: @attributes, children: @children, input: input, errors: errors, }.merge(args) self.class.new(**args) end def type self.class.type end def ==(other) name && type == other.type && name == other.name end # @abstract def to_ast raise NotImplementedError end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
formalist-0.9.0 | lib/formalist/element.rb |
formalist-0.8.0 | lib/formalist/element.rb |