Skip to content

リリース 2.2

以下の変更が準備され、実装されました。

アトリビュート

Internalアトリビュート

  • inclusionオプションのサポートが追加されました;
  • mustオプションのサポートが追加されました;
  • ヘルパーのサポートが追加されました。

Outputアトリビュート

  • inclusionオプションのサポートが追加されました;
  • mustオプションのサポートが追加されました;
  • ヘルパーのサポートが追加されました。

オプション

  • consists_ofオプションにネストされた値の検証が追加されました。

メソッド

メソッドsuccess!

サービスを手動で早期に成功完了するための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

メソッドfail!

fail!メソッドにtypeアトリビュートが追加されました。 デフォルトでは、アトリビュートの値は:baseです。 任意の名前を指定し、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

サービスの結果

フック

このリリースでは、サービスの結果を処理する別のアプローチが追加されました。 Resultに2つのフックのサポートが追加されました。

詳細

フックon_success

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

フックon_failure

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

その他

このリリースにはその他の修正と改善も含まれています。