Previous Basic Usage | Next Advanced Usage
The Steps DSL provides Given, and_then, Continue, and and_expose for expressing complex workflows clearly.
class User::Creation < Solid::Process
input do
attribute :email, :string
attribute :name, :string
end
def call(attributes)
rollback_on_failure {
Given(attributes)
.and_then(:validate_email) # ← Stops here if Failure
.and_then(:create_user)
}.and_expose(:user_created, [:user])
end
private
def validate_email(email:, **)
return Failure(:email_taken) if User.exists?(email:)
Continue()
end
def create_user(email:, name:, **)
user = User.create!(email:, name:)
Continue(user:)
end
endNote: Using
create!insiderollback_on_failurelets exceptions trigger automatic rollback. For manual control, usecreateand check.persisted?.
Given(attributes)— starts the step chain with initial dataand_then(:method)— calls a method; short-circuits on FailureContinue(hash)— merges data and proceeds to next stepand_expose(:type, [:keys])— ends chain with Success containing only specified keysrollback_on_failure { }— wraps steps in a database transaction- Always use
**in step method signatures to ignore extra keys
For detailed explanations, examples, and advanced patterns, see:
- Steps DSL — complete DSL reference
- Transactions — rollback strategies
Previous Basic Usage | Next Advanced Usage