A set of tools for building reliable services of any complexity.
Documentation
See servactory.com for documentation.
Quick Start
Installation
gem "servactory"
Define service
class UserService::Authenticate < Servactory::Base
input :email, type: String
input :password, type: String
output :user, type: User
private
def call
if (user = User.authenticate_by(email: inputs.email, password: inputs.password)).present?
outputs.user = user
else
fail!(message: "Authentication failed")
end
end
end
Usage in controller
class SessionsController < ApplicationController
def create
service_result = UserService::Authenticate.call(**session_params)
if service_result.success?
session[:current_user_id] = service_result.user.id
redirect_to service_result.user
else
flash.now[:message] = service_result.error.
render :new
end
end
private
def session_params
params.require(:session).permit(:email, :password)
end
end
Contributing
This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the Contributor Covenant code of conduct. We recommend reading the contributing guide as well.
License
Servactory is available as open source under the terms of the MIT License.