Getting started
Conventions
- All services are subclasses of
Servactory::Base
and are located in theapp/services
directory. It is common practice to create and inherit fromApplicationService::Base
, which is a subclass ofServactory::Base
. - Name services by what they do, not by what they accept. Use verbs in names. For example,
UsersService::Create
instead ofUsersService::Creation
.
Installation
Add this to Gemfile
:
ruby
gem "servactory"
And execute:
shell
bundle install
Preparation
As a first step, it is recommended to prepare the base class for further inheritance.
ApplicationService::Exceptions
ruby
module ApplicationService
module Exceptions
class Input < Servactory::Exceptions::Input; end
class Output < Servactory::Exceptions::Output; end
class Internal < Servactory::Exceptions::Internal; end
class Failure < Servactory::Exceptions::Failure; end
end
end
ApplicationService::Base
ruby
module ApplicationService
class Base < Servactory::Base
configuration do
input_exception_class ApplicationService::Exceptions::Input
internal_exception_class ApplicationService::Exceptions::Internal
output_exception_class ApplicationService::Exceptions::Output
failure_class ApplicationService::Exceptions::Failure
end
end
end