What is a usual step input?

  • A usual step input passes a symbol in in: that matches an existing organizer instance method. Convenient Service calls that method and forwards its return value to the step under the same name.

    class CalculateDoubled
      include ConvenientService::Standard::Config
    
      attr_reader :number
    
      def initialize(number:)
        @number = number
      end
    
      def result
        success(doubled: number * 2)
      end
    end
    
    class AwardLoyaltyPoints
      include ConvenientService::Standard::Config
    
      step CalculateDoubled,
        in: :number,
        out: {doubled: :points}
    
      private
    
      def number
        21
      end
    end
    
    result = AwardLoyaltyPoints.result
    
    result.success?
    # => true
    
    result.data[:points]
    # => 42
  • in: :number calls number on the organizer (AwardLoyaltyPoints) and passes its return value as number: to the step (CalculateDoubled).

  • Only a Symbol is accepted - a String (e.g. in: "number") raises UnsupportedKeyType exception.

  • This is the default step input type - use it whenever the step's parameter name already matches an organizer method name. When the names differ, use a step alias input instead.

See also

Sources