Factlink / pavlov

Provides a Command/Query/Interactor framework.
MIT License
22 stars 4 forks source link

Validations via ActiveModel::Errors #57

Closed marten closed 10 years ago

marten commented 10 years ago

This is a rough first spike.

The user must end her valid? method with errors.empty? or otherwise a false value will be returned if the last check was fine (errors.add(:title, 'must mention pavlov') unless title =~ /pavlov/ returns nil if the title mentions Pavlov).

Therefore, it would be better if the user implemented some other method, and valid? would be a library method that simply returns errors.empty? That valid? method should probably be public now, since we want to check validity before calling operations.

A sensible name for the method that the user should implement would be validate, but that's already taken by a method that would possibly be better named check_validation (since it's similar to check_authorization).

The names of various methods could ideally be cleaned up, but that's hard to do backwards-compatibly. For consistent naming, the user should have to implement validate, authorize, execute. But that means swapping the meaning of validate and valid? with respect to the current way.

But replacing def valid? with def validate might not be such a big deal.

In summary: I'd love some feedback on how we could do this while maintaining a smooth upgrade path.

markijbema commented 10 years ago

I agree on the reasoning on validate. I think that's a good way to implement that. As said in the other pullrequest, I think the semantics of authorized? returning boolean is better.

marten commented 10 years ago

I think this can be merged now.

markijbema commented 10 years ago

The build is failing though?