Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/servactory/servactory
Powerful Service Object for Ruby applications
https://github.com/servactory/servactory
rails ruby ruby-on-rails servactory service-factory service-object service-objects services
Last synced: 4 days ago
JSON representation
Powerful Service Object for Ruby applications
- Host: GitHub
- URL: https://github.com/servactory/servactory
- Owner: servactory
- License: mit
- Created: 2023-04-28T21:40:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-09T10:30:25.000Z (13 days ago)
- Last Synced: 2024-12-18T17:55:53.614Z (4 days ago)
- Topics: rails, ruby, ruby-on-rails, servactory, service-factory, service-object, service-objects, services
- Language: Ruby
- Homepage: https://servactory.com
- Size: 1.79 MB
- Stars: 20
- Watchers: 5
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
A set of tools for building reliable services of any complexity.## Documentation
See [servactory.com](https://servactory.com) for documentation.
## Quick Start
### Installation
```ruby
gem "servactory"
```### Define service
```ruby
class UserService::Authenticate < Servactory::Base
input :email, type: String
input :password, type: Stringoutput :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
```ruby
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
endprivate
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](http://contributor-covenant.org) code of conduct.
We recommend reading the [contributing guide](https://servactory.com/CONTRIBUTING) as well.## License
Servactory is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).