Skip to content

Service call ​

Services are called via .call or .call! methods.

Method .call! ​

The .call! method throws an exception if any problem occurs within the service.

ruby
Users::Accept.call!(user: User.first)
ruby
# => #<ApplicationService::Result @failure?=false, @success?=true, @user=..., @user?=true>
ruby
# => ApplicationService::Exceptions::Input: [Users::Accept] Required input `user` is missing

# => ApplicationService::Exceptions::Failure: There is some problem with the user

Method .call ​

The .call method throws an exception for input, internal, and output attribute problems. Other errors are captured and provided via the Result class.

ruby
Users::Accept.call(user: User.first)
ruby
# => #<ApplicationService::Result @failure?=false, @success?=true, @user=..., @user?=true>
ruby
# => ApplicationService::Exceptions::Input: [Users::Accept] Required input `user` is missing

# => #<ApplicationService::Result @error=There is some problem with the user, @failure?=true, @success?=false>