Configuration

Operandi provides a flexible configuration system that allows you to customize behavior at three levels: global, per-service, and per-call.

Global Configuration

Configure Operandi globally using an initializer. For Rails applications, create config/initializers/operandi.rb:

Operandi.configure do |config|
  # Type enforcement
  config.require_arg_type = true        # Require type option for all arguments
  config.require_output_type = true     # Require type option for all outputs

  # Transaction settings
  config.use_transactions = true        # Wrap each service in a database transaction

  # Error behavior
  config.load_errors = true             # Copy errors to parent service in context chain
  config.break_on_error = true          # Stop step execution when an error is added
  config.raise_on_error = false         # Raise an exception when an error is added
  config.rollback_on_error = true       # Rollback transaction when an error is added

  # Warning behavior
  config.load_warnings = true           # Copy warnings to parent service in context chain
  config.break_on_warning = false       # Stop step execution when a warning is added
  config.raise_on_warning = false       # Raise an exception when a warning is added
  config.rollback_on_warning = false    # Rollback transaction when a warning is added
end

Default Values

Option
Default
Description

require_arg_type

true

Raises Operandi::MissingTypeError when defining arguments without a type option

require_output_type

true

Raises Operandi::MissingTypeError when defining outputs without a type option

use_transactions

true

Wraps service execution in ActiveRecord::Base.transaction

load_errors

true

Propagates errors to parent service when using .with(self)

break_on_error

true

Stops executing remaining steps when an error is added

raise_on_error

false

Raises Operandi::Error when an error is added

rollback_on_error

true

Rolls back the transaction when an error is added

load_warnings

true

Propagates warnings to parent service when using .with(self)

break_on_warning

false

Stops executing remaining steps when a warning is added

raise_on_warning

false

Raises Operandi::Error when a warning is added

rollback_on_warning

false

Rolls back the transaction when a warning is added

Per-Service Configuration

Override global configuration for a specific service class using the config class method:

Per-Call Configuration

Override configuration for a single service call:

Configuration Precedence

Configuration is merged in this order (later overrides earlier):

  1. Global configuration (from initializer)

  2. Per-service configuration (from config class method)

  3. Per-call configuration (from run or with arguments)

Common Configuration Patterns

Strict Mode for Critical Services

Fire-and-Forget Services

Background Job Services

Type Enforcement (Enabled by Default)

By default, all arguments and outputs must have a type option. This helps catch type-related bugs early and makes your services self-documenting.

To disable type enforcement globally (not recommended):

Or disable for specific services:

You can also control them independently:

Disabling Transactions

If you're not using ActiveRecord or want to manage transactions yourself:

Or disable for specific services:

When use_transactions is true, Operandi uses ActiveRecord::Base.transaction(requires_new: true) to create savepoints, allowing nested services to rollback independently.

What's Next?

Now that you understand configuration, learn about the core concepts:

Next: Concepts

Last updated