Release 2.2
The following changes have been prepared and implemented.
Attributes
Internal Attribute
- Added support for the
inclusionoption; - Added support for the
mustoption; - Added support for helpers.
Output Attribute
- Added support for the
inclusionoption; - Added support for the
mustoption; - Added support for helpers.
Options
- Added nested value validation for the
consists_ofoption.
Methods
Method success!
Added the success! method for manually completing the service early with success.
ruby
class UsersService::Confirmation::Send < ApplicationService::Base
input :user, type: User
make :skip_if_already_sent!
# ...
def skip_if_already_sent!
return if user.need_confirmation?
success!
end
# ...
endMethod fail!
Added the type attribute for the fail! method. By default, the attribute has the value :base. You can specify any name and then use it when handling Failure.
ruby
class UsersService::Confirmation::Send < ApplicationService::Base
input :user, type: User
make :skip_if_already_sent!
# ...
def skip_if_already_sent!
return if user.need_confirmation?
fail!(:soft, message: "The confirmation has already been sent")
end
# ...
endService Result
Hooks
This release adds another approach to handling the service result. Support for two hooks has been added for Result.
Hook on_success
ruby
UsersService::Confirmation::Send
.call(user:)
.on_success do |outputs:|
redirect_to outputs.notification
endHook on_failure
ruby
UsersService::Confirmation::Send
.call(user:)
.on_failure(:all) do |exception:|
flash.now[:message] = exception.message
render :new
endOther
This release also contains other fixes and improvements.