Quickstart
Operandi are framework-agnostic and can be used in any Ruby project.
Installation
Add this line to your application's Gemfile:
gem "operandi", "~> 3.0"Or you can install it yourself by running:
bundle add operandi --version "~> 3.0"Create ApplicationService
ApplicationServiceFor Rails Applications
If you're using Rails, you can use the install generator to set up Operandi automatically:
bin/rails generate operandi:installThis will create the ApplicationService base class, an initializer, and a spec file (if RSpec is detected). See Rails Generators for more details.
For Non-Rails Applications
First, create a folder for your services. The path will depend on the framework you are using. For Rails, you can create a folder in app/services.
Next, create your base class. You can name it as you wish, but we recommend ApplicationService.
Create Your First Service
Now let's create our first service. We'll make a simple service that returns a greeting message.
Run the Service
Now you can run your service from anywhere in your application.
Check for Success or Failure
Raise on Error with run!
run!Use run! when you want errors to raise exceptions instead of being collected:
This is equivalent to:
What's Next?
Learn how to configure Operandi for your application:
Last updated