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/definition.rb,
lib/formalist/element/class_interface.rb,
lib/formalist/element/permitted_children.rb
Direct Known Subclasses
Formalist::Elements::Attr, Formalist::Elements::CompoundField, Formalist::Elements::Field, Formalist::Elements::Group, Formalist::Elements::Many, Formalist::Elements::Section
Defined Under Namespace
Modules: ClassInterface Classes: Attributes, Definition, PermittedChildren
Instance Attribute Summary collapse
- #attributes ⇒ Object readonly private
- #children ⇒ Object readonly private
- #errors ⇒ Object readonly private
- #input ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(*args, attributes, children, input, errors) ⇒ Element
constructor
private
A new instance of Element.
- #to_ast ⇒ Object abstract
-
#type ⇒ Symbol
Returns the element’s type, which is a symbolized, camlized representation of the element’s class name.
Methods included from ClassInterface
attribute, attributes_schema, permitted_children, type
Constructor Details
#initialize(*args, attributes, children, input, 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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/formalist/element.rb', line 13 def initialize(*args, attributes, children, input, errors) # Set supplied attributes or their defaults full_attributes = self.class.attributes_schema.each_with_object({}) { |(name, defn), memo| value = attributes[name] || defn[:default] memo[name] = value unless value.nil? } # Then run them through the schema @attributes = Types::Hash.schema(self.class.attributes_schema.map { |name, defn| [name, defn[:type]] }.to_h).(full_attributes) @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.
10 11 12 |
# File 'lib/formalist/element.rb', line 10 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.
10 11 12 |
# File 'lib/formalist/element.rb', line 10 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.
10 11 12 |
# File 'lib/formalist/element.rb', line 10 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.
10 11 12 |
# File 'lib/formalist/element.rb', line 10 def input @input end |
Instance Method Details
#to_ast ⇒ Object
47 48 49 |
# File 'lib/formalist/element.rb', line 47 def to_ast raise NotImplementedError end |
#type ⇒ Symbol
Returns the element’s type, which is a symbolized, camlized representation of the element’s class name.
This is a critical hook for customising form rendering when using custom form elements, since the type in this case will be based on the name of form element’s sublass.
42 43 44 |
# File 'lib/formalist/element.rb', line 42 def type self.class.type end |