Class: ActiverecordCallbackLens::Parser::ConditionParser
- Inherits:
-
Object
- Object
- ActiverecordCallbackLens::Parser::ConditionParser
- Defined in:
- lib/activerecord_callback_lens/parser/condition_parser.rb
Overview
Turns a CallbackDefinition’s raw if/unless conditions into a structured ConditionTree.
Proc/Lambda conditions are parsed by reading their source file with Prism, isolating the enclosing lambda/block node by line number, and recursively mapping the boolean AST (‘&&`, `||`, `!`, predicate calls) onto ConditionTree nodes. Symbol conditions become MethodRefNodes whose expansion is deferred to the MethodResolver. Any other entry kind (e.g. ActiveModel’s framework injected Conditionals::Value guard on after_* callbacks) is ignored.
Parsing never raises on missing or unreadable source: a nil source_location or a missing file is skipped silently, and a Prism parse failure warns to $stderr while leaving the condition unresolved.
Defined Under Namespace
Classes: LambdaLocator
Class Method Summary collapse
-
.parse(definition) ⇒ Collector::CallbackDefinition
A copy with condition_tree populated.
Instance Method Summary collapse
-
#initialize(definition) ⇒ ConditionParser
constructor
A new instance of ConditionParser.
-
#parse ⇒ Collector::CallbackDefinition
A copy with condition_tree set.
Constructor Details
#initialize(definition) ⇒ ConditionParser
Returns a new instance of ConditionParser.
31 32 33 |
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 31 def initialize(definition) @definition = definition end |
Class Method Details
.parse(definition) ⇒ Collector::CallbackDefinition
Returns a copy with condition_tree populated.
26 27 28 |
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 26 def self.parse(definition) new(definition).parse end |
Instance Method Details
#parse ⇒ Collector::CallbackDefinition
Returns a copy with condition_tree set.
36 37 38 |
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 36 def parse @definition.with(condition_tree: build_tree) end |