Skip to content

Rails Generators

Servactory provides Rails generators for common tasks.

Installation generator Since 2.5.0

Sets up the base service infrastructure.

shell
bundle exec rails g servactory:install

Generated files

FileDescription
app/services/application_service/base.rbBase service class
app/services/application_service/exceptions.rbException classes
app/services/application_service/result.rbResult class

Options

OptionDefaultDescription
--pathapp/servicesOutput directory
--namespaceApplicationServiceBase namespace

Examples

shell
# Default installation
bundle exec rails g servactory:install

# Custom namespace
bundle exec rails g servactory:install --namespace=MyApp::Services

# Custom path
bundle exec rails g servactory:install --path=lib/services

Service generator Since 2.5.0

Creates a new service with typed inputs.

shell
bundle exec rails g servactory:service NAME [inputs...]

Options

OptionDefaultDescription
--pathapp/servicesOutput directory

Type shortcuts

SyntaxResult
name or name:stringinput :name, type: String
age:integerinput :age, type: Integer
active:booleaninput :active, type: [TrueClass, FalseClass]
user:Userinput :user, type: User
items:arrayinput :items, type: Array
data:hashinput :data, type: Hash

Examples

shell
# Basic service
bundle exec rails g servactory:service users_service/create

# With typed inputs
bundle exec rails g servactory:service orders_service/process user:User amount:integer

# Nested namespace
bundle exec rails g servactory:service admin/reports/generate started_on:date ended_on:date

RSpec generator Since 2.5.0

Creates an RSpec test file for a service.

shell
bundle exec rails g servactory:rspec NAME [inputs...]

Options

OptionDefaultDescription
--pathspec/servicesOutput directory

Examples

shell
# Generate spec matching service inputs
bundle exec rails g servactory:rspec users_service/create first_name last_name email

# For existing service
bundle exec rails g servactory:rspec orders_service/process

Extension generator Since 3.0.0

Creates a new extension module.

shell
bundle exec rails g servactory:extension NAME

Options

OptionDefaultDescription
--pathapp/services/application_service/extensionsOutput directory
--namespaceApplicationServiceBase namespace

Examples

shell
# Basic extension
bundle exec rails g servactory:extension Auditable

# Nested namespace
bundle exec rails g servactory:extension Admin::AuditTrail

# Custom path
bundle exec rails g servactory:extension Cacheable --path=lib/extensions

See Extensions for usage details.