Class: Synthra::Parser::AST::SchemaNode
- Defined in:
- lib/synthra/parser/ast.rb
Overview
Schema definition node
Represents a complete schema definition in the DSL. A SchemaNode contains the schema name, list of fields, and any schema-level behaviors.
Instance Attribute Summary collapse
-
#behaviors ⇒ Object
readonly
Returns the value of attribute behaviors.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_name ⇒ Object
readonly
Returns the value of attribute parent_name.
Instance Method Summary collapse
-
#initialize(name:, fields: [], behaviors: [], parent_name: nil, line: nil) ⇒ SchemaNode
constructor
Create a new SchemaNode.
-
#to_schema ⇒ Synthra::Schema
Convert this AST node to a Schema object.
Constructor Details
#initialize(name:, fields: [], behaviors: [], parent_name: nil, line: nil) ⇒ SchemaNode
Create a new SchemaNode
133 134 135 136 137 138 139 |
# File 'lib/synthra/parser/ast.rb', line 133 def initialize(name:, fields: [], behaviors: [], parent_name: nil, line: nil) super(line: line) @name = name @fields = fields @behaviors = behaviors @parent_name = parent_name end |
Instance Attribute Details
#behaviors ⇒ Object (readonly)
Returns the value of attribute behaviors.
116 117 118 |
# File 'lib/synthra/parser/ast.rb', line 116 def behaviors @behaviors end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
110 111 112 |
# File 'lib/synthra/parser/ast.rb', line 110 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
104 105 106 |
# File 'lib/synthra/parser/ast.rb', line 104 def name @name end |
#parent_name ⇒ Object (readonly)
Returns the value of attribute parent_name.
122 123 124 |
# File 'lib/synthra/parser/ast.rb', line 122 def parent_name @parent_name end |
Instance Method Details
#to_schema ⇒ Synthra::Schema
Convert this AST node to a Schema object
Creates a Synthra::Schema instance from this node, converting all child nodes (fields, behaviors) as well.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/synthra/parser/ast.rb', line 153 def to_schema all_behaviors = behaviors.map(&:to_behavior) # Extract version from behaviors version_behavior = all_behaviors.find { |b| b[:name] == :version } version = version_behavior&.dig(:value) # Extract deprecated from behaviors deprecated_behavior = all_behaviors.find { |b| b[:name] == :deprecated } deprecated = !deprecated_behavior.nil? = deprecated_behavior&.dig(:value) # Filter out version/deprecated from runtime behaviors runtime_behaviors = all_behaviors.reject { |b| [:version, :deprecated].include?(b[:name]) } Schema.new( name: name, fields: fields.map(&:to_field), behaviors: runtime_behaviors, metadata: {}, version: version, deprecated: deprecated, deprecation_message: ) end |