Class: SimpleCovMcp::PredicateEvaluator
- Inherits:
-
Object
- Object
- SimpleCovMcp::PredicateEvaluator
- Defined in:
- lib/simplecov_mcp/predicate_evaluator.rb
Overview
Evaluates coverage predicates from either Ruby code strings or files. Used by the validate subcommand, validate MCP tool, and library API.
Security Warning: Predicates execute as arbitrary Ruby code with full system privileges. Only use predicates from trusted sources.
Class Method Summary collapse
-
.evaluate_code(code, model) ⇒ Boolean
Evaluate a predicate from a code string.
-
.evaluate_file(path, model) ⇒ Boolean
Evaluate a predicate from a file.
Class Method Details
.evaluate_code(code, model) ⇒ Boolean
Evaluate a predicate from a code string
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simplecov_mcp/predicate_evaluator.rb', line 17 def self.evaluate_code(code, model) # WARNING: The predicate code executes with full Ruby privileges. # It has unrestricted access to the file system, network, and system commands. # Only use predicate code from trusted sources. # # We evaluate in a fresh Object context to prevent accidental access to # internals, but this provides NO security isolation. evaluation_context = Object.new predicate = evaluation_context.instance_eval(code, '<predicate>', 1) validate_callable(predicate) predicate.call(model) rescue SyntaxError => e raise "Syntax error in predicate code: #{e.}" end |
.evaluate_file(path, model) ⇒ Boolean
Evaluate a predicate from a file
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/simplecov_mcp/predicate_evaluator.rb', line 39 def self.evaluate_file(path, model) unless File.exist?(path) raise "Predicate file not found: #{path}" end content = File.read(path) # WARNING: The predicate code executes with full Ruby privileges. # It has unrestricted access to the file system, network, and system commands. # Only use predicate files from trusted sources. # # We evaluate in a fresh Object context to prevent accidental access to # internals, but this provides NO security isolation. evaluation_context = Object.new predicate = evaluation_context.instance_eval(content, path, 1) validate_callable(predicate) predicate.call(model) rescue SyntaxError => e raise "Syntax error in predicate file: #{e.}" end |