Skip to content

アクションのオプション

オプションif

メソッド呼び出しの前にif条件を確認します。

ruby
make :something,
     if: ->(context:) { Settings.features.preview.enabled }

def something
  # ...
end

オプションunless

ifオプションの逆です。

ruby
make :something,
     unless: ->(context:) { Settings.features.preview.disabled }

def something
  # ...
end

オプションposition

すべてのメソッドにはポジションがあります。 positionを使用すると、makeで追加された時点とは異なるタイミングでメソッドを呼び出せます。 サービスの継承で便利です。

ruby
class SomeApiService::Base < ApplicationService::Base
  make :api_request!,
       position: 2

  # ...
end

class SomeApiService::Posts::Create < SomeApiService::Base
  input :post_name, type: String

  # ...
  
  make :validate!,
       position: 1

  private

  def validate!
    # ...
  end

  # ...
end