Class: Foxtail::Bundle::Scope
- Inherits:
-
Object
- Object
- Foxtail::Bundle::Scope
- Defined in:
- lib/foxtail/bundle/scope.rb
Overview
Variable scope and state management during resolution Corresponds to fluent-bundle/src/scope.ts
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#bundle ⇒ Object
readonly
Returns the value of attribute bundle.
-
#dirty ⇒ Object
readonly
Returns the value of attribute dirty.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
-
#add_error(message) ⇒ Object
Add an error to the collection.
-
#all_variables ⇒ Object
Get all available variables (locals + args).
-
#child_scope ⇒ Object
Create a child scope (for function calls).
-
#clear_locals ⇒ Object
Reset locals (used in some resolution contexts).
-
#initialize(bundle, **args) ⇒ Scope
constructor
A new instance of Scope.
-
#release(id) ⇒ Object
Release tracking of a message/term ID.
-
#set_local(name, value) ⇒ Object
Set a local variable (used within functions).
-
#track(id) ⇒ Object
Track a message/term ID to detect circular references.
-
#tracking?(id) ⇒ Boolean
Check if an ID is currently being tracked (circular reference check).
-
#variable(name) ⇒ Object
Get a variable value (checks locals first, then args).
Constructor Details
#initialize(bundle, **args) ⇒ Scope
Returns a new instance of Scope.
14 15 16 17 18 19 20 |
# File 'lib/foxtail/bundle/scope.rb', line 14 def initialize(bundle, **args) @bundle = bundle @args = args # External variables passed to format() @locals = {} # Local variables (set within functions) @errors = [] # Error collection during resolution @dirty = Set.new # Circular reference detection (message/term IDs) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'lib/foxtail/bundle/scope.rb', line 9 def args @args end |
#bundle ⇒ Object (readonly)
Returns the value of attribute bundle.
8 9 10 |
# File 'lib/foxtail/bundle/scope.rb', line 8 def bundle @bundle end |
#dirty ⇒ Object (readonly)
Returns the value of attribute dirty.
12 13 14 |
# File 'lib/foxtail/bundle/scope.rb', line 12 def dirty @dirty end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/foxtail/bundle/scope.rb', line 11 def errors @errors end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
10 11 12 |
# File 'lib/foxtail/bundle/scope.rb', line 10 def locals @locals end |
Instance Method Details
#add_error(message) ⇒ Object
Add an error to the collection
43 |
# File 'lib/foxtail/bundle/scope.rb', line 43 def add_error() = @errors << |
#all_variables ⇒ Object
Get all available variables (locals + args)
60 |
# File 'lib/foxtail/bundle/scope.rb', line 60 def all_variables = @args.merge(@locals) |
#child_scope ⇒ Object
Create a child scope (for function calls)
49 50 51 52 53 54 |
# File 'lib/foxtail/bundle/scope.rb', line 49 def child_scope(**) child = self.class.new(@bundle, **@args, **) child.instance_variable_set(:@locals, @locals.dup) child.instance_variable_set(:@dirty, @dirty.dup) child end |
#clear_locals ⇒ Object
Reset locals (used in some resolution contexts)
57 |
# File 'lib/foxtail/bundle/scope.rb', line 57 def clear_locals = @locals.clear |
#release(id) ⇒ Object
Release tracking of a message/term ID
40 |
# File 'lib/foxtail/bundle/scope.rb', line 40 def release(id) = @dirty.delete(id) |
#set_local(name, value) ⇒ Object
Set a local variable (used within functions)
26 |
# File 'lib/foxtail/bundle/scope.rb', line 26 def set_local(name, value) = @locals[name.to_sym] = value |
#track(id) ⇒ Object
Track a message/term ID to detect circular references
29 30 31 32 33 34 35 36 37 |
# File 'lib/foxtail/bundle/scope.rb', line 29 def track(id) if @dirty.include?(id) add_error("Circular reference detected: #{id}") return false end @dirty.add(id) true end |
#tracking?(id) ⇒ Boolean
Check if an ID is currently being tracked (circular reference check)
46 |
# File 'lib/foxtail/bundle/scope.rb', line 46 def tracking?(id) = @dirty.include?(id) |
#variable(name) ⇒ Object
Get a variable value (checks locals first, then args)
23 |
# File 'lib/foxtail/bundle/scope.rb', line 23 def variable(name) = @locals[name.to_sym] || @args[name.to_sym] |