Class: Synthra::Parser::AST::FieldNode
- Defined in:
- lib/synthra/parser/ast.rb
Overview
Field definition node
Represents a single field within a schema. Contains the field name, type information, optional flag, conditions, and behaviors.
Instance Attribute Summary collapse
-
#behaviors ⇒ Object
readonly
Returns the value of attribute behaviors.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#type_node ⇒ Object
readonly
Returns the value of attribute type_node.
Instance Method Summary collapse
-
#initialize(name:, type_node:, optional: false, condition: nil, behaviors: [], line: nil) ⇒ FieldNode
constructor
Create a new FieldNode.
-
#optional? ⇒ Boolean
Check if this field is optional.
-
#to_field ⇒ Synthra::Field
Convert this AST node to a Field object.
Constructor Details
#initialize(name:, type_node:, optional: false, condition: nil, behaviors: [], line: nil) ⇒ FieldNode
Create a new FieldNode
240 241 242 243 244 245 246 247 |
# File 'lib/synthra/parser/ast.rb', line 240 def initialize(name:, type_node:, optional: false, condition: nil, behaviors: [], line: nil) super(line: line) @name = name @type_node = type_node @optional = optional @condition = condition @behaviors = behaviors end |
Instance Attribute Details
#behaviors ⇒ Object (readonly)
Returns the value of attribute behaviors.
228 229 230 |
# File 'lib/synthra/parser/ast.rb', line 228 def behaviors @behaviors end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
222 223 224 |
# File 'lib/synthra/parser/ast.rb', line 222 def condition @condition end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
204 205 206 |
# File 'lib/synthra/parser/ast.rb', line 204 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
216 217 218 |
# File 'lib/synthra/parser/ast.rb', line 216 def optional @optional end |
#type_node ⇒ Object (readonly)
Returns the value of attribute type_node.
210 211 212 |
# File 'lib/synthra/parser/ast.rb', line 210 def type_node @type_node end |
Instance Method Details
#optional? ⇒ Boolean
Check if this field is optional
254 255 256 |
# File 'lib/synthra/parser/ast.rb', line 254 def optional? @optional end |
#to_field ⇒ Synthra::Field
Convert this AST node to a Field object
Creates a Synthra::Field instance from this node.
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/synthra/parser/ast.rb', line 269 def to_field Field.new( name: optional? ? "#{name}?" : name, type_name: type_node.name, type_args: type_node.arguments, nullable: type_node.nullable?, condition: condition&.field_name, behaviors: behaviors.map(&:to_field_behavior) ) end |