Sha256: d8f91381d9b4ab3465455f9c55e781cc3cae60c9c6f647f031f61c19b27c46d9

Contents?: true

Size: 820 Bytes

Versions: 5

Compression:

Stored size: 820 Bytes

Contents

module Flows
  class Result
    # Shortcuts for building result objects
    module Helpers
      private

      def ok(status = :success, **data)
        Flows::Result::Ok.new(data, status: status)
      end

      def err(status = :failure, **data)
        Flows::Result::Err.new(data, status: status)
      end

      def match_ok(status = nil)
        if status
          lambda do |result|
            result.is_a?(Flows::Result::Ok) &&
              result.status == status
          end
        else
          Flows::Result::Ok
        end
      end

      def match_err(status = nil)
        if status
          lambda do |result|
            result.is_a?(Flows::Result::Err) &&
              result.status == status
          end
        else
          Flows::Result::Err
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flows-0.3.0 lib/flows/result/helpers.rb
flows-0.2.0 lib/flows/result/helpers.rb
flows-0.1.0 lib/flows/result/helpers.rb
flows-0.0.2 lib/flows/result/helpers.rb
flows-0.0.1 lib/flows/result/helpers.rb