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

Feature/114 comparing two properties #143

Closed
wants to merge 7 commits into from
Closed

Feature/114 comparing two properties #143

wants to merge 7 commits into from

Conversation

paw3lx
Copy link
Collaborator

@paw3lx paw3lx commented Dec 5, 2017

Info

This Pull Request is related to issue no. #114

After the latest problems with develop branch I talked to @GooRiOn. We decided that the best will be to create new PR on this repo instead of my fork.

I will just copy/paste notes from previous PR:
Guys, I added few lines of code to provide possibility to compare two properties. It's just a draft, so please take a look. I was not sure about it so I just added one Ensure method and one test to test if it's working.
I think that now we have two possibilities:

  • To have many Ensure methods. They can look like in this PR

  • Replace Ensure methods to have only one way of creating ValitRules. This could be big change I guess. As @GooRiOn said, it could piss off all folks that use Valit.
    What do you think?

Changes

  • Added Ensure method to provide functionality of comparing two properties

@codecov
Copy link

codecov bot commented Dec 5, 2017

Codecov Report

Merging #143 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           develop   #143   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files           39     39           
  Lines          763    805   +42     
======================================
+ Hits           763    805   +42
Impacted Files Coverage Δ
src/Valit/Rules/NestedObjectCollectionValitRule.cs 100% <ø> (ø) ⬆️
src/Valit/Rules/ValitRuleExtensions.cs 100% <100%> (ø) ⬆️
src/Valit/Rules/ValitRule.cs 100% <100%> (ø) ⬆️
src/Valit/Rules/ValitRuleAccessorExtensions.cs 100% <100%> (ø) ⬆️
src/Valit/ValitRules.cs 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04d2b49...2385d28. Read the comment docs.

Copy link
Member

@GooRiOn GooRiOn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't get the part related to the GetEnsureRules :/ Could you explain it a little bit? According to your question whether we should stick to one/many Ensure, after a while I'd go for many overloads. Let folks decide which selector is fine for which validation.

@paw3lx
Copy link
Collaborator Author

paw3lx commented Dec 6, 2017

Ok, I will try to explain this.
So basically our goal is to get all rules from the chain passed in Ensure function. To do this we have to call GetAllEnsureRules on the result from ruleFunc delegate (Func<IValitRule<TObject, TProperty>, TObject, IValitRule<TObject, TProperty>>). So now we need call ruleFunc and to do this we need an instance of TObject. This is done inside GetEnsureRules function: _ruleFunc(this, @object).GetAllEnsureRules();

We cannot do this inside Ensure function because we don't have TObject instance. So we need to do this later, when Validate function is called.

I hope that you understand my explanation. As I said at the beginning this is just an idea. Maybe you will come up with better solution :)

@GooRiOn
Copy link
Member

GooRiOn commented Dec 7, 2017

Now I get this :D So to things I noticed:

  • In your Ensure() overload you can get rid of GetAllEnsureRules() since it always returns 1 item
  • I'd move EnsureRules to IValitRuleAccessor since it should not be exposed to the users

I also think that the Validate() and ValidateRule are now too complicated right now, but unfortunetly, I have no idea how to simplify this. Any suggestion @arekbal @tdeschryver ?

@timdeschryver
Copy link
Collaborator

@GooRiOn I'm a bit busy atm.
I'll get back to this in the weekend/next week.

@paw3lx
Copy link
Collaborator Author

paw3lx commented Dec 8, 2017

In your Ensure() overload you can get rid of GetAllEnsureRules() since it always returns 1 item

Done

I'd move EnsureRules to IValitRuleAccessor since it should not be exposed to the users

Done as well. To do this I had to create new IValitRuleAccessor. Please check if everything is ok.

@timdeschryver
Copy link
Collaborator

@GooRiOn the methods seems fine to me.
Maybe the only thing would be to change _strategy.Fail so it returns a bool instead of using an out parameter for it?

@@ -119,23 +129,41 @@ IValitResult IValitRules<TObject>.Validate(Func<IValitRule<TObject>, bool> predi
private IValitResult Validate(IEnumerable<IValitRule<TObject>> rules)
{
var result = ValitResult.Success;

foreach(var rule in rules.ToList())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something that is changed in this PR, but why is the .ToList() needed here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid multiple enumerations

@GooRiOn
Copy link
Member

GooRiOn commented Dec 11, 2017

@tdeschryver agree with your statements but I think we should discuss how to simplify this code. I do what I does but it quite complicated and duplicates the code responsible for handling validation. As I mentioned before, the issue is that I can't come up with any better idea now. It just looks to me that we could do this better (and this applies also to my valit rules responsible for handling nested objects and collection where this code is also duplicated).

@timdeschryver
Copy link
Collaborator

Gotya!

@GooRiOn
Copy link
Member

GooRiOn commented Dec 12, 2017

Created an issue for the duplication #150

@GooRiOn GooRiOn added the 1.0.0 label Dec 13, 2017
@paw3lx
Copy link
Collaborator Author

paw3lx commented Dec 28, 2017

I removed the out argument from ValidateRule. It looks a little bit simpler. What do you think guys? Do you have any idea what else we could simplify?

Copy link
Member

@GooRiOn GooRiOn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paw3lx could we do some Skype/Hangout call, so you could explain the whole flow to me? I guess I know what happens here, but would be great to confirm that during the call. It'd be way simpler for me to understand the whole thing. Also, I could explain my PR to you as well :)

@paw3lx
Copy link
Collaborator Author

paw3lx commented Dec 29, 2017

@GooRiOn Yes, sure. Just contact me and we can do some Skype call :) I think you have my email or snapchat.

@GooRiOn
Copy link
Member

GooRiOn commented Oct 7, 2018

This PR is not resolved for too long. Need to close it :(

@GooRiOn GooRiOn closed this Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants