These are chat archives for dry-rb/chat

5th
Sep 2018
Jonah
@jonahx
Sep 05 2018 14:56
I’ve written a little utility for creating functional command objects without boilerplate, and using DI via constructor injection (without going the full bore container route). Would love feedback on the interface:
class CreateUser

  extend CommandObject

  dependencies user_repo: UserRepo, email_service: MyEmailService
  input :name, :email, :password
  steps(
    :validate_input,
    :ensure_unique_email,
    :insert_user,
    :send_confirmation
  )

  private
  #
  # implementation methods here...
end

# Used like:
create_user = CreateUser.new
create_user.(name: 'John', email: 'john@gmail.com', password: 'secret')
Pablo Crivella
@pablocrivella
Sep 05 2018 15:15
Are you using dry-transaction for that?
If so, how does it haddle custom step addapters like map, check etc?
Jonah
@jonahx
Sep 05 2018 15:56
@pablocrivella no, i’m not. it’s just a small stand-alone utility class. i just stole the name steps because it seemed to fit.