Class: Synthra::Parser::AST::BehaviorNode

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

Overview

Behavior annotation node

Represents a behavior declaration at schema or field level. Behaviors modify generation (latency, failure) or set metadata (seed).

Examples:

DSL

@latency 100..500ms
@failure 10%
@seed 12345

AST

BehaviorNode.new(name: :latency, value: 100..500)
BehaviorNode.new(name: :failure, value: 10)
BehaviorNode.new(name: :seed, value: 12345)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, line: nil) ⇒ BehaviorNode

Create a new BehaviorNode

Parameters:

  • name (String, Symbol)

    behavior name

  • value (Object)

    behavior value

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

    source line number



380
381
382
383
384
# File 'lib/synthra/parser/ast.rb', line 380

def initialize(name:, value:, line: nil)
  super(line: line)
  @name = name.to_sym
  @value = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



365
366
367
# File 'lib/synthra/parser/ast.rb', line 365

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



371
372
373
# File 'lib/synthra/parser/ast.rb', line 371

def value
  @value
end

Instance Method Details

#to_behaviorHash

Convert to behavior configuration hash for schema-level

Returns:

  • (Hash)

    behavior configuration hash



400
401
402
# File 'lib/synthra/parser/ast.rb', line 400

def to_behavior
  { name: name, value: value }
end

#to_field_behaviorSynthra::FieldBehavior

Convert to FieldBehavior for field-level behaviors

Returns:



391
392
393
# File 'lib/synthra/parser/ast.rb', line 391

def to_field_behavior
  FieldBehavior.new(type: name, value: value)
end