These are chat archives for dry-rb/chat

7th
Apr 2017
Daniel Draper
@danieldraper
Apr 07 2017 12:43
Hi - Wondering if there is anyone using gems from dry-rb in rails as commands/service objects/interactors and would be willing to share some example and experience. Initial thoughts would have me looking at dry-validation, dry-types, dry-transaction, dry-monads, dry-matchers maybe... or am I just talking crazy?
Piotr Solnica
@solnic
Apr 07 2017 13:00
@danieldraper we use it all for this type of objects, without rails though, but it shouldn’t matter
for multi-step commands that should work as a transaction where steps are relatively complex and should be standalone dry-transaction is pretty cool
for simpler stuff dry-matcher is nice with its result-matching API (although it’s less powerful than in dry-transaction, we’ll probably port it over to dry-matcher because why not)
and with types/validation, go nuts with both, whatever works good for you will be fine, both gems have a ton of use cases
Daniel Draper
@danieldraper
Apr 07 2017 13:04
Thanks @solnic really love the concepts sparked by a function oo talk you did however currently stuck using Rails lots to learn all at once. Any recommendations for starting points? Currently want to accept form input then pass params to object that is validated and persisted also love the idea of immutable objects
Piotr Solnica
@solnic
Apr 07 2017 13:14
@danieldraper with dry-validation you want to validate data, so just the params hash, then (if you need to), pass the validated data to an object
Daniel Draper
@danieldraper
Apr 07 2017 13:15
Thanks, came across the last link today but haven't actually had a read yet. Will check it out
Daniel Draper
@danieldraper
Apr 07 2017 14:48
@solnic wasn't as difficult as expected thanks for your help. I have a working operation, form and validation in rails.
Took some inspiration from the berg project. I do have a question where does this block behaviour come from is it the command/ROM as it doesn't seem to be working in rails?
Operations::Admin::Events::Create.(params[:event]) do |m|
  m.success do
    flash[:notice] = t('admin.events.event_created')
    redirect_to admin_events_path
  end

  m.failure do |validation|
    render :new
  end
end
This works, just doesn't read as nice :smile:
op = Operations::Admin::Events::Create.(params[:event])
if op.success?
  flash[:notice] = t('admin.events.event_created')
  redirect_to admin_events_path
else
  render :new
end
Piotr Solnica
@solnic
Apr 07 2017 15:05
@danieldraper matching API comes from dry-matcher, but it’s extended further in dry-transaction so that you can match on detailed errors (ie m.error(:auth_failure) { … }). We’ll unify this soon so dry-matcher has the same power and ships with a couple additional extensions (we have them already in our apps at Icelab, just need to pull that out into the gems)
Daniel Draper
@danieldraper
Apr 07 2017 15:06
Ah of course, thanks
Have you used the dry-rb architecture on large projects? I have a side project I'm considering the dry-rb architecture for its currently hundreds of models and controllers
Daniel Draper
@danieldraper
Apr 07 2017 16:04
Ended up using dry-container, dry-validation, dry-monads and dry-matcher for now and quite happy with the result so far, seem to have some strange loading issues and need to manually require everywhere but suspect that is a rails related issue.
Thanks for you help @solnic :+1:
Piotr Solnica
@solnic
Apr 07 2017 16:06
@danieldraper cool :)
@danieldraper re large projects, define “large project” first
Daniel Draper
@danieldraper
Apr 07 2017 16:09

@solnic Not really a large project yet but lots more to build and just lots of small moving parts 2.5 years side project so far www.memberhub.com.au.

This is the current stats (rails project)
Controllers - 150
Models - 120
Lines - 16k

Piotr Solnica
@solnic
Apr 07 2017 16:14
the one I’m working on is around 20kCLOC
can’t provide controllers/models stats though as it’s uncomparable with rails
Daniel Draper
@danieldraper
Apr 07 2017 16:14
Completely understand
Piotr Solnica
@solnic
Apr 07 2017 16:15
1605CLOC in our routes (kinda comparable with rails controllers)
2770CLOC in domain operation objects
1242CLOC in entity classes
Daniel Draper
@danieldraper
Apr 07 2017 16:15
Little overwhelming considering dry-rb for a new project like this even though I can see the benefits there is a bit of a learning curve (probably said the same thing when I switched from .NET to Ruby :D)
Piotr Solnica
@solnic
Apr 07 2017 16:16
1186CLOC in repository classes
696CLOC in persistence part (relations / low-level commands)
yeah there’s a learning curve for sure
esp that lots of docs are missing
and there are some rough edges / missing features here and there