Class: Synthra::Parser::AST::SchemaReferenceNode

Inherits:
TypeNode
  • Object
show all
Defined in:
lib/synthra/parser/ast.rb

Overview

Schema reference node

Represents an explicit schema reference using the syntax: schema(:Name) or schema(:Name).array

This is the ONLY valid way to reference schemas in the new DSL. The system must NEVER infer schemas from capitalization.

Examples:

DSL

user: schema(:User)
users: schema(:User).array
users: schema(:User).array(1..10)

AST

SchemaReferenceNode.new(schema_name: "User")
SchemaReferenceNode.new(schema_name: "User", array: true)
SchemaReferenceNode.new(schema_name: "User", array: true, array_range: 1..10)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_name:, array: false, array_range: nil, optional: false, line: nil) ⇒ SchemaReferenceNode

Create a new SchemaReferenceNode

Parameters:

  • schema_name (String)

    name of the referenced schema

  • array (Boolean) (defaults to: false)

    whether this is an array

  • array_range (Range, nil) (defaults to: nil)

    optional array size range

  • optional (Boolean) (defaults to: false)

    whether the reference is optional

  • line (Integer, nil) (defaults to: nil)

    source line number



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lib/synthra/parser/ast.rb', line 1077

def initialize(schema_name:, array: false, array_range: nil, optional: false, line: nil)
  super(
    name: "schema_ref",
    arguments: {
      schema_name: schema_name,
      array: array,
      array_range: array_range
    },
    nullable: optional,
    line: line
  )
  @schema_name = schema_name
  @array = array
  @array_range = array_range
  @optional = optional
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



1054
1055
1056
# File 'lib/synthra/parser/ast.rb', line 1054

def array
  @array
end

#array_rangeObject (readonly)

Returns the value of attribute array_range.



1060
1061
1062
# File 'lib/synthra/parser/ast.rb', line 1060

def array_range
  @array_range
end

#optionalObject (readonly)

Returns the value of attribute optional.



1066
1067
1068
# File 'lib/synthra/parser/ast.rb', line 1066

def optional
  @optional
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



1048
1049
1050
# File 'lib/synthra/parser/ast.rb', line 1048

def schema_name
  @schema_name
end

Instance Method Details

#array?Boolean

Check if this is an array reference

Returns:

  • (Boolean)

    true if array



1099
1100
1101
# File 'lib/synthra/parser/ast.rb', line 1099

def array?
  @array
end

#optional?Boolean

Check if this is an optional reference

Returns:

  • (Boolean)

    true if optional



1108
1109
1110
# File 'lib/synthra/parser/ast.rb', line 1108

def optional?
  @optional
end