Class: SpecForge::Attribute::Variable
- Inherits:
-
Attribute
- Object
- Attribute
- SpecForge::Attribute::Variable
- Includes:
- Chainable
- Defined in:
- lib/spec_forge/attribute/variable.rb
Overview
Represents a variable reference in a template
Variables are resolved at runtime by looking up values stored in the current execution context. Supports dot notation for accessing nested properties (e.g., "response.body.id").
Constant Summary
Constants included from Chainable
Instance Attribute Summary
Attributes included from Chainable
#header, #invocation_chain, #keyword
Instance Method Summary collapse
-
#base_object ⇒ Object
Returns the base object for this variable from the current context.
-
#initialize ⇒ Variable
constructor
Creates a new variable attribute.
Methods included from Chainable
Constructor Details
#initialize ⇒ Variable
Creates a new variable attribute
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spec_forge/attribute/variable.rb', line 28 def initialize(...) super # Unset the keyword to keep chainable from displaying it in error messages @keyword = nil sections = @input.split(".") @header = sections.first&.to_sym @invocation_chain = sections[1..] || [] end |
Instance Method Details
#base_object ⇒ Object
Returns the base object for this variable from the current context
Looks up the variable name in the current Forge context's variables. Raises an error if the variable is not defined.
49 50 51 52 53 54 55 56 57 |
# File 'lib/spec_forge/attribute/variable.rb', line 49 def base_object variables = @options[:context] || Forge.context&.variables || {} if !variables.key?(variable_name) raise Error::MissingVariableError.new(variable_name, available_variables: variables.keys) end variables[variable_name] end |