Class: Synthra::Parser::AST::ConditionNode
- Defined in:
- lib/synthra/parser/ast.rb
Overview
Condition node for conditional fields
Represents the condition part of a conditional field (if ...). The condition references another field that must be truthy.
Constant Summary collapse
- DANGEROUS_METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Dangerous method names that should never be allowed in conditions
%w[class instance_eval eval send __send__ method_missing].freeze
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
Instance Method Summary collapse
-
#evaluate(context) ⇒ Boolean
Evaluate the condition against a context.
-
#initialize(field_name:, line: nil) ⇒ ConditionNode
constructor
Create a new ConditionNode.
Constructor Details
#initialize(field_name:, line: nil) ⇒ ConditionNode
Create a new ConditionNode
435 436 437 438 |
# File 'lib/synthra/parser/ast.rb', line 435 def initialize(field_name:, line: nil) super(line: line) @field_name = field_name end |
Instance Attribute Details
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
427 428 429 |
# File 'lib/synthra/parser/ast.rb', line 427 def field_name @field_name end |
Instance Method Details
#evaluate(context) ⇒ Boolean
Evaluate the condition against a context
Checks if the referenced field has a truthy value in the given context. Security: Only uses hash access, never method calls, and validates field names against a whitelist of dangerous methods.
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/synthra/parser/ast.rb', line 456 def evaluate(context) # Security: Only use hash access, never public_send # Reject dangerous field names that could be exploited field_name_str = @field_name.to_s return false if field_name_str.start_with?("__") # Whitelist validation: reject dangerous method names return false if self.class::DANGEROUS_METHODS.include?(field_name_str) return false unless context.respond_to?(:[]) value = context[@field_name] || context[@field_name.to_sym] !!value end |