Introduction
Teckel provides a common interface for wrapping your ruby business logic into,
with enforced input, output and error data structures.
The two main components are Operations and Chains.
Motivation
Working with Interactor, Trailblazer's Operation and Dry-rb's Transaction and probably a hand full of inconsistent "service objects", I missed a system that:
- provides and enforces well defined input, output and error structures
- makes chaining multiple operation easy and reliable
- is easy to debug
About Code Samples
Code samples are tested using byexamples.
They all use a common base setup to have some fake objects to work with:
# frozen_string_literal: true
require "English"
require 'dry-types'
require 'dry-struct'
Warning[:experimental] = false if Warning.respond_to? :[]
module Types
include Dry.Types()
end
module FakeDB
Rollback = Class.new(RuntimeError)
def self.transaction
yield
rescue Rollback
# doing rollback ...
raise
end
end
class User
def initialize(name:, age:)
@name, @age = name, age
end
attr_reader :name, :age
def save
!underage?
end
def errors
underage? ? [{ age: "underage" }] : nil
end
def underage?
@age <= 18
end
end
Last update: 2021-09-28 15:32:53