Skip to content

Release 2.2

The following changes have been prepared and implemented.

Attributes

Internal Attribute

  • Added support for the inclusion option;
  • Added support for the must option;
  • Added support for helpers.

Output Attribute

  • Added support for the inclusion option;
  • Added support for the must option;
  • Added support for helpers.

Options

  • Added nested value validation for the consists_of option.

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

  # ...
end

Method 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

  # ...
end

Service Result

Hooks

This release adds another approach to handling the service result. Support for two hooks has been added for Result.

More details.

Hook on_success

ruby
UsersService::Confirmation::Send
  .call(user:)
  .on_success do |outputs:| 
    redirect_to outputs.notification
  end

Hook on_failure

ruby
UsersService::Confirmation::Send
  .call(user:)
  .on_failure(:all) do |exception:| 
    flash.now[:message] = exception.message
    render :new
  end

Other

This release also contains other fixes and improvements.