Class: Formalist::Element
- Inherits:
-
Object
- Object
- Formalist::Element
- Extended by:
- ClassInterface
- Defined in:
- lib/formalist/element.rb,
lib/formalist/element/attributes.rb,
lib/formalist/element/class_interface.rb
Direct Known Subclasses
ChildForms::ChildForm, Formalist::Elements::Attr, Formalist::Elements::CompoundField, Formalist::Elements::Field, Formalist::Elements::Group, Formalist::Elements::Many, Formalist::Elements::ManyForms, Formalist::Elements::Section
Defined Under Namespace
Modules: ClassInterface Classes: Attributes
Instance Attribute Summary collapse
- #attributes ⇒ Object readonly private
- #children ⇒ Object readonly private
- #errors ⇒ Object readonly private
- #input ⇒ Object readonly private
- #name ⇒ Object readonly private
Class Method Summary collapse
- .build(**args) ⇒ Object private
- .fill(input: {}, errors: {}, **args) ⇒ Object private
Instance Method Summary collapse
- #==(other) ⇒ Object
- #fill(input: {}, errors: {}, **args) ⇒ Object
-
#initialize(name: nil, attributes: {}, children: [], input: nil, errors: []) ⇒ Element
constructor
private
A new instance of Element.
- #to_ast ⇒ Object abstract
- #type ⇒ Object
Methods included from ClassInterface
Constructor Details
#initialize(name: nil, attributes: {}, children: [], input: nil, errors: []) ⇒ Element
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Element.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/formalist/element.rb', line 22 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/formalist/element.rb', line 9 def attributes @attributes end |
#children ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/formalist/element.rb', line 9 def children @children end |
#errors ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/formalist/element.rb', line 9 def errors @errors end |
#input ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/formalist/element.rb', line 9 def input @input end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/formalist/element.rb', line 9 def name @name end |
Class Method Details
.build(**args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/formalist/element.rb', line 12 def self.build(**args) new(**args) end |
.fill(input: {}, errors: {}, **args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/formalist/element.rb', line 17 def self.fill(input: {}, errors: {}, **args) new(**args).fill(input: input, errors: errors) end |
Instance Method Details
#==(other) ⇒ Object
53 54 55 |
# File 'lib/formalist/element.rb', line 53 def ==(other) name && type == other.type && name == other.name end |
#fill(input: {}, errors: {}, **args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/formalist/element.rb', line 35 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 |
#to_ast ⇒ Object
58 59 60 |
# File 'lib/formalist/element.rb', line 58 def to_ast raise NotImplementedError end |
#type ⇒ Object
49 50 51 |
# File 'lib/formalist/element.rb', line 49 def type self.class.type end |