Sha256: f92fefb65798a9ccd7d4596309d5a5428d264c81dff187a1eb1f61c810091cbb

Contents?: true

Size: 523 Bytes

Versions: 4

Compression:

Stored size: 523 Bytes

Contents

# frozen_string_literal: true

module Pipeable
  module Steps
    # Messages a risky operation which may pass or fail.
    class Try < Abstract
      def initialize *positionals, catch:, **keywords
        super(*positionals, **keywords)
        @catch = catch
      end

      def call result
        result.fmap { |operation| operation.public_send(*base_positionals, **base_keywords) }
      rescue *Array(catch) => error
        Failure error.message
      end

      private

      attr_reader :catch
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pipeable-0.4.0 lib/pipeable/steps/try.rb
pipeable-0.3.0 lib/pipeable/steps/try.rb
pipeable-0.2.0 lib/pipeable/steps/try.rb
pipeable-0.1.0 lib/pipeable/steps/try.rb