Class: Synthra::Parser::AST::SchemaDefinitionNode
- Defined in:
- lib/synthra/parser/ast.rb
Overview
Schema definition node (new syntax)
Represents a schema definition using the new Simulyra syntax:
schema Name:
This differs from the legacy SchemaNode which just uses Name:
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.
Instance Method Summary collapse
-
#initialize(name:, fields: [], behaviors: [], line: nil) ⇒ SchemaDefinitionNode
constructor
Create a new SchemaDefinitionNode.
-
#to_schema ⇒ Synthra::Schema
Convert to Schema object.
Constructor Details
#initialize(name:, fields: [], behaviors: [], line: nil) ⇒ SchemaDefinitionNode
Create a new SchemaDefinitionNode
812 813 814 815 816 817 |
# File 'lib/synthra/parser/ast.rb', line 812 def initialize(name:, fields: [], behaviors: [], line: nil) super(line: line) @name = name @fields = fields @behaviors = behaviors end |
Instance Attribute Details
#behaviors ⇒ Object (readonly)
Returns the value of attribute behaviors.
802 803 804 |
# File 'lib/synthra/parser/ast.rb', line 802 def behaviors @behaviors end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
796 797 798 |
# File 'lib/synthra/parser/ast.rb', line 796 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
790 791 792 |
# File 'lib/synthra/parser/ast.rb', line 790 def name @name end |
Instance Method Details
#to_schema ⇒ Synthra::Schema
Convert to Schema object
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/synthra/parser/ast.rb', line 824 def to_schema all_behaviors = behaviors.map(&:to_behavior) version_behavior = all_behaviors.find { |b| b[:name] == :version } version = version_behavior&.dig(:value) deprecated_behavior = all_behaviors.find { |b| b[:name] == :deprecated } deprecated = !deprecated_behavior.nil? = deprecated_behavior&.dig(:value) 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 |