Sha256: b6193f811de48532b676e57fea6250ae3cbac66dc35d2d60611550ffe9c2d597

Contents?: true

Size: 739 Bytes

Versions: 11

Compression:

Stored size: 739 Bytes

Contents

# frozen_string_literal: true

require "marameters"

module Pipeable
  module Steps
    # Delegates to a non-callable object which automatically wraps the result if necessary.
    class To < Abstract
      def initialize(object, message, **)
        super(**)
        @object = object
        @message = message
      end

      def call result
        result.bind do |arguments|
          splat = Marameters.categorize object.method(message).parameters, arguments
          wrap object.public_send(message, *splat.positionals, **splat.keywords, &splat.block)
        end
      end

      private

      attr_reader :object, :message

      def wrap(result) = result.is_a?(Dry::Monads::Result) ? result : Success(result)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pipeable-1.1.0 lib/pipeable/steps/to.rb
pipeable-1.0.0 lib/pipeable/steps/to.rb
pipeable-0.14.0 lib/pipeable/steps/to.rb
pipeable-0.13.0 lib/pipeable/steps/to.rb
pipeable-0.12.0 lib/pipeable/steps/to.rb
pipeable-0.11.0 lib/pipeable/steps/to.rb
pipeable-0.10.0 lib/pipeable/steps/to.rb
pipeable-0.9.1 lib/pipeable/steps/to.rb
pipeable-0.9.0 lib/pipeable/steps/to.rb
pipeable-0.8.0 lib/pipeable/steps/to.rb
pipeable-0.7.0 lib/pipeable/steps/to.rb