Code Monkey home page Code Monkey logo

dry-transaction-extra's Introduction

Hi there ๐Ÿ‘‹

I'm Paul Sadauskas, and usually go by TheAmazingRando on the internet. I love Ruby and have been a Rails developer since there was a Rails (deployed my first application on 0.11 in 2005). I was a member of the DataMapper and Merb core teams, and have contributed to many open-source projects (both Ruby and non-Ruby) over the years.

  • ๐Ÿ”ญ Iโ€™m currently working on:
    • Scalar.sh โ€” A tool to autoscale servers with a simple configuration.
    • Logsnarf - A tool that receives your logs and write metrics to your TSDB.
  • ๐ŸŒฑ Iโ€™m currently learning Rust and woodworking.
  • ๐Ÿ’ฌ Ask me about Hanami, Dry-rb and the non-Rails Ruby ecosystem
  • ๐Ÿ“ซ How to reach me: Links are over there โ†ฉ๏ธ
  • ๐Ÿ˜„ Pronouns: he/him

dry-transaction-extra's People

Contributors

paul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

adamjsimon

dry-transaction-extra's Issues

Additional custom step functions

Hi, a big thanks for this gem.

I just watched your talk from RubyConf 2021 and came to your github profile looking to see if you had shared any of the custom step functions you talked about.

Boy was I lucky that this gem has just been created a month ago.

I understand that this gem is very new, but I was just wondering if you were intending to add async and authorize step functions in future. I saw that you had implemented them previously in a gist

I also note the README does also provide an example of how you might use validation before running async jobs, is this your preferred approach now, rather than using a custom step function?

Anyway, if adding these is not part of your future plans and you have no objection to them being included, I wondered if I might try adding them in a PR?

Cheers, Dylan

Validate extension block behaviour

I have been using the validation extension, however I have noticed that it has to be explicitly called on the object otherwise it is not run.

The documentation reads

In addition to the valid step adapter, Dry::Transaction::Extra has support for an explicit "pre-flight" validation that runs as the first step.

class CreateUser
  include Dry::Transaction
  include Dry::Transaction::Extra
  load_extensions :validation

  validate do
    params do
      required(:name).filled(:string)
      optional(:email).maybe(:string)
    end
  end

  step :create_user
end

This is useful if you want to, for example, run the transaction as an async background job, but want to first verify the arguments to the job before enqueueing it. If the job is going to fail anyway, why bother creating it in the first place?

result = CreateUser.validator.new.call(params)
CreateUserJob.perform_async(params) unless result.failure?

Problem

Correct me If I am misunderstanding, but I took this to read that the validation will automatically be run as the first step when calling CreateUser.new.call(params) in addition to being able to call it explicitly with CreateUser.validator.new.call(params)

I could instead use the valid step function, however for small uncomplicated validations I find the brief extension syntax and lack of an additional file to be easier.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.