A set of tools for building reliable services of any complexity.
๐ Documentation
See servactory.com for comprehensive documentation, including:
- Detailed guides for all features
- Advanced configuration options
- Best practices and patterns
- Migration guides
- API reference
๐ก Why Servactory?
Building reliable services shouldn't be complicated. Servactory provides a battle-tested framework for creating service objects with:
- ๐ก๏ธ Type Safety - Enforce types on inputs and outputs, catch errors early
- โ Built-in Validation - Rich validation DSL with custom rules
- ๐งช Test-Friendly - RSpec matchers for easy testing
- ๐ Structured Output - Consistent Result object pattern
- ๐ง Highly Configurable - Extensions, helpers, and custom options
- ๐ Well Documented - Comprehensive guides and examples
๐ Quick Start
Installation
gem "servactory"Define service
class UserService::Authenticate < Servactory::Base
input :email, type: String
input :password, type: String
output :user, type: User
make :authenticate!
private
def authenticate!
if (user = User.authenticate_by(email: inputs.email, password: inputs.password)).present?
outputs.user = user
else
fail!(message: "Authentication failed", meta: { email: inputs.email })
end
end
endUsage in controller
class SessionsController < ApplicationController
def create
service = UserService::Authenticate.call(**session_params)
if service.success?
session[:current_user_id] = service.user.id
redirect_to service.user
else
flash.now[:alert] = service.error.message
render :new, status: :unprocessable_entity
end
end
private
def session_params
params.require(:session).permit(:email, :password)
end
end๐ค Contributing
We love contributions! Check out our Contributing Guide to get started.
Ways to contribute:
- ๐ Report bugs and issues
- ๐ก Suggest new features
- ๐ Improve documentation
- ๐งช Add test cases
- ๐ง Submit pull requests
๐ Acknowledgments
Special thanks to all our contributors!
๐ License
Servactory is available as open source under the terms of the MIT License.