Skip to content
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 key.success? and key.failure? predicates #615

Open
flash-gordon opened this issue Jan 15, 2020 · 12 comments
Open

Add key.success? and key.failure? predicates #615

flash-gordon opened this issue Jan 15, 2020 · 12 comments

Comments

@flash-gordon
Copy link
Member

In complex rules, it may be useful to know whether the key has any failure message already.

rule(:foos).each do
  key.success? # => true
  key.failure? # => false
  key.failure('wrong')
  key.success? # => false
  key.failure? # => true
end
@waiting-for-dev
Copy link
Member

If it's ok, I'll give a try to it.

@flash-gordon
Copy link
Member Author

Sure.

@waiting-for-dev
Copy link
Member

Hmmm this seems tricky... it implies changing the architecture so that the evaluator and failures for every key are shared between all rules. Am I wrong?

@flash-gordon
Copy link
Member Author

For me, it would be enough to work only within a single rule run. Though I can see how it can be not immediately obvious. @solnic any thoughts?

@flash-gordon
Copy link
Member Author

rule.failure? or something along the lines could be another approach

@waiting-for-dev
Copy link
Member

Probably rule.failure? makes more sense, as key.failure? implies that key(name).failure? should work. However, the scenario where evaluator is shared also makes sense for even more complex rules :)

@solnic
Copy link
Member

solnic commented Jan 17, 2020

I forgot we have error?. Currently it expects path arg but we can set it to the default key, so you could have:

rule(:foo) do
  error? # expands to `error?("foo")`
  
  error?("other.path") # if you need to check something else
end

I think this should be enough and we don't need key.failure/success?.

@flash-gordon
Copy link
Member Author

works for me though rule.error?/rule.failure? still could be useful

@solnic
Copy link
Member

solnic commented Jan 17, 2020

@flash-gordon why?

@flash-gordon
Copy link
Member Author

@solnic rules can be quite convoluted, especially in macros. This is the exact need I had when filed this issue. Keeping them simple is not always feasible.

@solnic
Copy link
Member

solnic commented Jan 17, 2020

@flash-gordon ok makes sense

@flash-gordon
Copy link
Member Author

@waiting-for-dev so I think adding a default argument to error? would be enough here. I can add a separate feature request about rule.error?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants