I'm not using the mutations gem, but I created two libraries which kind of
do the same thing, albeit separately.
The first is form validations - I use Forme, and I wanted to be able to
pass objects to represent the form state and validation cycle. It copies
the same validation structure as Sequel (and most of the validations are
almost 1-to-1 copies of the validation implementation).
If my form object validates, I may call a command object to complete a
complex action, keeping my routes (I use Roda) very request/response
specific. This library is paired with the Wisper gem to give me a very nice
callback-style syntax.
Here's a bit of the code in action (a Roda route). The form is obviously
Machine::CreateForm, and the Sequel interactions happen inside the
CreateMachine command.
r.post true do
check_machine_count_limit(rodauth.current_account_group)
@schema = Machine::CreateForm.new(r.params["form"])
r.halt view("machines/new") if @schema.invalid?
CreateMachine.call(@schema, account_group:
rodauth.current_account_group) do
on(:ok) do |machine, password|
flash[:password] = password if password
r.redirect machine_path(machine)
end
on(:no_compute_node) do
Mailer.error_email("No compute node available")
r.halt 422, view("machines/new", locals: { error: "No compute
nodes available" })
end
on(:no_ip_address) do
Mailer.error_email("No IP Address available")
r.halt 422, view("machines/new", locals: { error: "No IP
address available" })
end
on(:exception) do |e|
Mailer.error_email(e)
message = App.production? ? "An error occured" : e.message
r.halt 422, view("machines/new", locals: { error: message })
end
end
end
I might extract these two libraries from my project and release them as
gems if they gain a bit more maturity, but so far, I like the composition
of them when completing complex actions crossing multiple models with many
different failures. I don't use them for the normal CRUD style actions.
On Saturday, April 29, 2017 at 9:53:24 PM UTC-4, dota? =op wrote:
>
> i just found this gem:
>
> https://github.com/cypriss/mutations
>
> and wondered if someone is using it with sequel.
>
> how do you validate your models? do you keep all validation logic
> inside teh Command?
>
> any tips on coupling with sequel?
>
> --
> Igor
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.