Module: Musa::REPL::CustomizableDSLContext
- Defined in:
- lib/musa-dsl/repl/repl.rb
Overview
Mixin for DSL contexts that can be bound to a REPL.
This module provides the interface required for a DSL context to work with the REPL server. Classes that include this module can execute REPL-sent code in their own context, making their DSL methods available to live coding clients.
Requirements
Classes that include this module must implement the #binder method, which should return a Ruby Binding object representing the execution context.
Integration with DynamicProxy
Typically used with Musa::Extension::DynamicProxy::DynamicProxy:
class MyDSL
include CustomizableDSLContext
def initialize
@repl = REPL.new(bind: Musa::Extension::DynamicProxy::DynamicProxy.new(self))
end
protected def binder
@__binder ||= binding
end
# DSL methods available in REPL:
def play(note)
# ...
end
end
Execution Context
Code sent via REPL is evaluated in the binding returned by #binder, giving it access to:
- Instance variables of the DSL context
- All DSL methods (public and private)
- Local variables captured in the binding
Instance Method Summary collapse
-
#execute(source_block, file, line) ⇒ Object
Executes source code in the DSL context.
Instance Method Details
#execute(source_block, file, line) ⇒ Object
Executes source code in the DSL context.
Called by the REPL to evaluate received code blocks. Delegates to Binding#eval with the binding provided by #binder.
Parameters
- source_block: Ruby code as string
- file: Filename for error reporting (typically '(repl)')
- line: Starting line number for error reporting
Error Handling
Exceptions raised during evaluation propagate to the caller (REPL), which formats them and sends them to the client.
751 752 753 |
# File 'lib/musa-dsl/repl/repl.rb', line 751 def execute(source_block, file, line) binder.eval source_block, file, line end |