In my codebase I’m currently using dry-monads to implement a command pattern and dry-validation to perform validations on a per-command basis. Something like:
module Users
class Register < BaseCommand
class Contract < BaseContract
params do
email
name
etc....
end
end
def call(params)
yield Contract.call(params)
account = Accounts::Create.call(some_param: params[:some], other_param: params[:other])
yield do_account_setup_stuff(account: account, **params)
yield Users::SendEmail.call(account: params[:email], **params)
....
Success(account)
end
def do_account_setup_stuff(account:, another_thing:)
# do stuff
end
In my base contract class I have
def self.call(params)
new.call(params).to_monad
end
so I can yield the results of the contract. My base command class does a similar thing, just instantiates the class and calls it.
Am I doing this all wrong? Everything feels pretty good except as you can see I ended up having to do a lot of weird stuff with the params
being passed in. Since the contract needs everything in order to validate, but the other methods or other commands that compose this one don’t, I splat a lot of stuff I don’t need in order to cut down on wordiness or am forced to pull each arg out of the params hash. After all of this though, it just seems like a weird version of trailblazer and I can’t tell if I’m using these gems they way they were intended. Thanks so much in advance.