Skip to content

servactory/servactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

632 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Servactory

A set of tools for building reliable services of any complexity.

Gem version Release Date Downloads Ruby version

πŸ“š 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 and service mocking helpers
  • πŸ“Š 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
end

Usage 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.