-
-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial rules context interface #675
Conversation
There is a problem with ruby 3. Looks like I have to wrap all the params passed to Contract#call with curly braces. This is actually going to be a breaking change for ruby 3. What do you think would be the best course of action here? |
And if I use context arg instead of kwarg - the problem is gone. |
@flash-gordon could you suggest what to do? I'm surprised doing |
It breaks in cases like age_contract.(age: 17) They have to be rewritten as |
How about something a bit more radical: def call(input = nil, input:, context:)
# ...
end Reasoning: forcing people to use literal hash syntax in Alternatively, we could mimic what dry-validation 0.x used to do - have a default context established via params and expose |
2.6.6 :001 > def call(input = nil, input:, context:)
2.6.6 :002 > p input
2.6.6 :003 > end
SyntaxError ((irb):1: duplicated argument name)
def call(input = nil, input:, context:)
^~~~~~ |
I don't think there's much evidence supporting this. Besides, this is a change in the language, not some fancy stuff we added.
Yeah, this would work. We would have to use |
@flash-gordon yeah with |
@solnic if you go with predefined context you'll need to copy it in |
Actually, the current implementation deals with it. Both initial contexts get kind of duplicated on Concurrent::Map initialization. |
I also can't quite say that I understood what are you folks trying to achieve. |
In rom-rb and probably some dry-rb libs, we have a standard way of providing options to an existing instance via method called Having said that, I think the PR is good as-is, it adds the feature with a minimum effort so I'm gonna merge it in 🙂 Thanks for working on this! |
I see now, thanks for the explanation. This |
@pyromaniac I think it could be useful, ie you could inject some default settings specific to your app and then still have the ability to override them at run-time. This has proven to be useful in other libs, that's why I thought about it here too. |
Yeah, sure, that's why I implemented both in this PR as you suggested, it makes total sense. I'm talking about |
Implements #674