dry-rb / dry-logic

Predicate logic with rule composition
https://dry-rb.org/gems/dry-logic/
MIT License
179 stars 66 forks source link

Fix NoMethodError when trying to get AST of a Builder's result. #107

Closed estum closed 1 year ago

estum commented 1 year ago

In the first pair of commits of the PR there are a couple of shared examples and updates of the Dry::Logic::Builder's unit specs which reproduces a raised exception in scenarios like the following :

Dry::Logic::Builder.() { key?(:speed) }.to_ast
#     NoMethodError:
#       undefined method `name' for #<Proc:0x000000010c8982a0 (lambda)>
#     
#                 predicate.name
#                          ^^^^^

This is fixed by an avoiding of extra predicate to proc coercion in Dry::Logic::Builder::Context#initialize. So now it is just passed into the Dry::Logic::Builder::Context#predicate which lets to keep a predicate's name.

estum commented 1 year ago

👀

solnic commented 1 year ago

@estum thank you!