https://github.com/getlago/turbine_service
A simple and lightweight gem to build a service oriented architecture in Ruby.
https://github.com/getlago/turbine_service
Last synced: 3 months ago
JSON representation
A simple and lightweight gem to build a service oriented architecture in Ruby.
- Host: GitHub
- URL: https://github.com/getlago/turbine_service
- Owner: getlago
- License: mit
- Created: 2024-09-26T13:37:50.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-11-05T17:14:19.000Z (7 months ago)
- Last Synced: 2025-03-10T00:55:56.757Z (3 months ago)
- Language: Ruby
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Turbine Service
## What's Turbine Service?
Turbine Service is a simple and lightweight gem to build a service oriented architecture in Ruby.
## Installation
Add this line to you application's Gemfile:
```ruby
gem 'turbine_service'
```And run:
```bash
bundle install
```## How to use Turbine Service?
### Basic usage:
```ruby
class MyService < Turbine::Service::Base
def initialize(my_args)
@my_args = my_argssuper # Don't forget to call super
enddef call
# Perform your service logic hereresult
end
endresult = MyService.call(my_args)
result.success? # => true
result.failure? # => false
result.raise_if_error! # => Turbine::Service::Result instance
```### With failures
```ruby
class MyService < Turbine::Service::Base
def initialize(my_args)
@my_args = my_argssuper # Don't forget to call super
enddef call
return result.not_found_failure!(resource: 'args') if @my_args.nil?
return result.unauthorized_failure! unless @my_args.user.admin?# Perform your service logic here
result
rescue StandardError => e
result.service_failure!(code: :my_error_code, message: e.message)
end
end# Let's imagine that a error occurred in the service
result = MyService.call(my_args)
result.success? # => false
result.failure? # => trueresult.error.code # => :my_error_code
result.raise_if_error! # => raises Turbine::ServiceFailure
```### With data attached to the result
```ruby
class MyService < Turbine::Service::Base
class Result < Turbine::Service::Result
attr_accessor :my_data
enddef initialize(my_args)
@my_args = my_argssuper # Don't forget to call super
enddef call
# Perform your service logic hereresult.my_data = 'result data'
result
end
endresult = MyService.call(my_args)
result.success? # => true
result.failure? # => false
result.raise_if_error! # => MyService::Result instanceresult.my_data # => 'result data'
```# Contributing
Bug reports and pull requests are welcome.
Here are some ways you can contribute:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new featuresTo get started with development and testing:
```bash
git clone https://github.com/getlago/turbine_service.git
cd turbine_service
bundle install# Run specs
bundle exec rspec
```