These are chat archives for dry-rb/chat

19th
Jul 2018
Chris Richards
@cmrichards
Jul 19 2018 13:14
Looks like you could use dry-validation to simulate the Specification Pattern ? https://en.wikipedia.org/wiki/Specification_pattern
Jonah
@jonahx
Jul 19 2018 17:10
@cmrichards dry-validatoin is built on dry-logic: http://dry-rb.org/gems/dry-logic/predicates/. afaict, dry-logic essentially is the specification pattern, or something close enough that you could consider it equivalent.
Chris Richards
@cmrichards
Jul 19 2018 20:16
@jonahx Is it possible to combine multiple validation schemas? e.g. Schema1.and(Schema2).and(Schema3).({ ... })
Jonah
@jonahx
Jul 19 2018 20:18
@cmrichards can you give an example of what you mean? logical ‘and’ doesn’t make sense to me as something at the schema level — id see that at the dry-logic / predicate level.
Chris Richards
@cmrichards
Jul 19 2018 20:23
@jonahx Looking at the Specification_pattern wikipedia page, it looks like you can combine together multiple specifications. Specifications look like schemas right?
var OverDue = new OverDueSpecification();
var NoticeSent = new NoticeSentSpecification();
var InCollection = new InCollectionSpecification();

// example of specification pattern logic chaining
var SendToCollection = OverDue.And(NoticeSent).And(InCollection.Not());

var InvoiceCollection = Service.GetInvoices();

foreach (var currentInvoice in InvoiceCollection) {
    if (SendToCollection.IsSatisfiedBy(currentInvoice))  {
        currentInvoice.SendToCollection();
    }
}
Jonah
@jonahx
Jul 19 2018 20:38
@cmrichards i can’t tell from the docs if you can do that directly swith schemas or not. you can definitely do it with dry-logic predicates.
i’d need to dig around further to tell but don’t have time atm
Sean Winner
@swinner2
Jul 19 2018 21:19
Is there any way to use https://github.com/DavyJonesLocker/client_side_validations with dry-validation?