Module: Dry::Mutations::Extensions

Defined in:
lib/dry/mutations/extensions/outcome.rb,
lib/dry/mutations/extensions/dummy.rb,
lib/dry/mutations/extensions/command.rb,
lib/dry/mutations/extensions/error_hash.rb,
lib/dry/mutations/extensions/error_array.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Command, Either, ErrorArray, ErrorHash, Hole, Pipe, Sieve, Wrapper

Constant Summary collapse

Dummy =

rubocop:disable Style/ConstantName

ENV['USE_SIEVE_AS_DUMMY'] ? Sieve : Pipe

Class Method Summary collapse

Class Method Details

.Either(input) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/dry/mutations/extensions/outcome.rb', line 79

def self.Either input
  case input
  when Class then input.prepend Either unless input.ancestors.include?(Either)
  when Module then input.include Either unless input.ancestors.include?(Either)
  else input.singleton_class.prepend Either unless input.singleton_class.ancestors.include?(Either)
  end
end

.Outcome(input) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dry/mutations/extensions/outcome.rb', line 90

def self.Outcome input
  case input
  when ::Mutations::Outcome then input
  when ::Dry::Monads::Either::Left
    ::Mutations::Outcome.new(false, nil, input.value, nil).tap do |outcome|
      ::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
    end
  when ::Dry::Monads::Either::Right
    ::Mutations::Outcome.new(true, input.value, nil, nil).tap do |outcome|
      ::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
    end
  when ->(inp) { inp.respond_to?(:success?) }
    ::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil).tap do |outcome|
      ::Dry::Mutations::Utils.extend_outcome outcome, input.host if input.respond_to?(:host)
    end
  else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]")
  end
end

.Outcome!(input) ⇒ Object



109
110
111
112
113
# File 'lib/dry/mutations/extensions/outcome.rb', line 109

def self.Outcome! input
  Outcome(input).tap do |outcome|
    fail ::Mutations::ValidationException.new(outcome.errors) unless outcome.success?
  end.value
end