Sha256: c127e6e9333c97c377812b9458f6deddff515afcf7f2ebe4f65344bd25b1b8fc

Contents?: true

Size: 725 Bytes

Versions: 3

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

module Fluxus
  module Results
    require 'fluxus/results/chainable'

    class Result
      include Chainable
      attr_reader :type, :data

      class StateNotImplemented < StandardError; end

      def initialize(type: :unknown, data: {})
        @type = type
        @data = data
        @state = define_state
      end

      def success?
        state == :success
      end

      def failure?
        state == :failure
      end

      def unknown?
        !(failure? || success?)
      end

      private

      attr_reader :state

      def define_state
        raise StateNotImplemented, 'the #define_state hook must be implemented by a concrete class'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluxus-1.0.0 lib/fluxus/results/result.rb
fluxus-0.1.2 lib/fluxus/results/result.rb
fluxus-0.1.0 lib/fluxus/results/result.rb