Class: Synthra::Parser::AST::ReferenceNode

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

Overview

Reference to another schema's field

Represents a Ref() expression that references a field from another schema. Used for cross-schema relationships.

Examples:

DSL

user_id: Ref(User.id)
category: Ref(Category.name)

AST

ReferenceNode.new(
  schema_name: "User",
  field_path: "id"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_name:, field_path:, line: nil) ⇒ ReferenceNode

Create a new ReferenceNode

Parameters:

  • schema_name (String)

    name of referenced schema

  • field_path (String)

    path to field in schema

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

    source line number



510
511
512
513
514
# File 'lib/synthra/parser/ast.rb', line 510

def initialize(schema_name:, field_path:, line: nil)
  super(line: line)
  @schema_name = schema_name
  @field_path = field_path
end

Instance Attribute Details

#field_pathObject (readonly)

Returns the value of attribute field_path.



501
502
503
# File 'lib/synthra/parser/ast.rb', line 501

def field_path
  @field_path
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



495
496
497
# File 'lib/synthra/parser/ast.rb', line 495

def schema_name
  @schema_name
end

Instance Method Details

#to_sString

Get full reference string

Examples:

ref.to_s  # => "User.id"

Returns:

  • (String)

    "SchemaName.field_path"



524
525
526
# File 'lib/synthra/parser/ast.rb', line 524

def to_s
  "#{schema_name}.#{field_path}"
end