Skip to content

Instantly share code, notes, and snippets.

View waiting-for-dev's full-sized avatar
🏠
Working from home

Marc Busqué waiting-for-dev

🏠
Working from home
View GitHub Profile
require 'logger'
require 'byebug'
require 'dry/monads'
require 'dry/monads/do'
require 'dry/matcher/result_matcher'
module Dry
module Transaction
module Steps
@waiting-for-dev
waiting-for-dev / dry_transaction_resurrection.rb
Last active December 30, 2021 12:53
POC for a new version of dry-transaction
# frozen_string_literal: true
require "dry/monads"
require "rspec"
require "ostruct"
module Dry
module TransactionResurrection
def self.[](monad)
Module.new do
@waiting-for-dev
waiting-for-dev / FIFO.ini
Last active November 17, 2021 09:32 — forked from hmijail/FIFO.ini
A CopyQ command to implement a Clipboard FIFO
[Command]
Command="
copyq:
maxrow = count() - 1
select(maxrow)
paste()
if (config('move') == 'true') {
remove(0)
} else {
remove(maxrow)
# frozen_string_literal: true
require 'octokit'
require 'faraday/retry'
class Updater
attr_reader :client
SOLIDUSIO = 'solidusio'

Unhappy path

Before delving into how we support database (DB) transactions, let's first consider how we can handle operations that only pertain to the unhappy path. This consideration is important because, as we will see, it will become relevant when we reach the main topic.

Most of the time, the unhappy path is something managed by the caller (e.g., a controller rendering an error in case of failure). However, there are situations where it makes sense to encapsulate part of the unhappy path within the operations class. For instance, you might want to log the failure somewhere.

When relying on the vanilla #steps method, the implementation is straightforward:

class CreateUser < Dry::Operation