Class: Phlexi::Field::Builder
- Inherits:
-
Structure::Node
- Object
- Structure::Node
- Phlexi::Field::Builder
- Includes:
- Phlex::Helpers, Options::Associations, Options::Attachments, Options::Descriptions, Options::Hints, Options::InferredTypes, Options::Labels, Options::Multiple, Options::Placeholders, Options::Validators
- Defined in:
- lib/phlexi/field/builder.rb
Overview
Builder class is responsible for building fields with various options and components.
Defined Under Namespace
Classes: DOM, FieldCollection
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
Attributes for the field.
-
#dom ⇒ Structure::DOM
readonly
The DOM structure for the field.
-
#object ⇒ Object
readonly
The object associated with the field.
-
#options ⇒ Hash
readonly
Options for the field.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Structure::Node
Instance Method Summary collapse
- #has_value? ⇒ Boolean
-
#initialize(key, parent:, object: nil, value: NIL_VALUE, **options) ⇒ Builder
constructor
Initializes a new FieldBuilder instance.
-
#repeated(collection = nil) {|block| ... } ⇒ FieldCollection
Creates a repeated field collection.
Methods included from Options::Attachments
Methods included from Options::Associations
Methods included from Options::Hints
Methods included from Options::Descriptions
#description, #has_description?
Methods included from Options::Placeholders
Methods included from Options::Labels
Methods included from Options::Multiple
Methods included from Options::InferredTypes
#inferred_field_component, #inferred_field_type, #inferred_string_field_type
Methods inherited from Structure::Node
Constructor Details
#initialize(key, parent:, object: nil, value: NIL_VALUE, **options) ⇒ Builder
Initializes a new FieldBuilder instance.
39 40 41 42 43 44 45 46 |
# File 'lib/phlexi/field/builder.rb', line 39 def initialize(key, parent:, object: nil, value: NIL_VALUE, **) super(key, parent: parent) @object = object @value = determine_initial_value(value) @options = @dom = self.class::DOM.new(field: self) end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Attributes for the field.
14 15 16 |
# File 'lib/phlexi/field/builder.rb', line 14 def attributes @attributes end |
#dom ⇒ Structure::DOM (readonly)
The DOM structure for the field.
14 15 16 |
# File 'lib/phlexi/field/builder.rb', line 14 def dom @dom end |
#object ⇒ Object (readonly)
The object associated with the field.
14 15 16 |
# File 'lib/phlexi/field/builder.rb', line 14 def object @object end |
#options ⇒ Hash (readonly)
Options for the field.
14 15 16 |
# File 'lib/phlexi/field/builder.rb', line 14 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
30 31 32 |
# File 'lib/phlexi/field/builder.rb', line 30 def value @value end |
Instance Method Details
#has_value? ⇒ Boolean
57 58 59 |
# File 'lib/phlexi/field/builder.rb', line 57 def has_value? .present? ? value.attached? : (value.present? || value == false) end |
#repeated(collection = nil) {|block| ... } ⇒ FieldCollection
Creates a repeated field collection.
53 54 55 |
# File 'lib/phlexi/field/builder.rb', line 53 def repeated(collection = nil, &) self.class::FieldCollection.new(field: self, collection:, &) end |