Module: Dry::Mutations::Extensions
- Defined in:
- lib/dry/mutations/extensions/outcome.rb,
lib/dry/mutations/extensions/dummy.rb,
lib/dry/mutations/extensions/command.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Command, Either, Hole, Pipe, Sieve, Wrapper
Constant Summary collapse
Class Method Summary collapse
-
.Either(input) ⇒ Object
rubocop:disable Style/MethodName.
- .Outcome(input) ⇒ Object
- .Outcome!(input) ⇒ Object
Class Method Details
.Either(input) ⇒ Object
rubocop:disable Style/MethodName
78 79 80 81 82 83 84 |
# File 'lib/dry/mutations/extensions/outcome.rb', line 78 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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dry/mutations/extensions/outcome.rb', line 89 def self.Outcome input case input when ::Mutations::Outcome then input when ::Dry::Monads::Either::Left ::Mutations::Outcome.new(false, nil, input.value, nil) when ::Dry::Monads::Either::Right ::Mutations::Outcome.new(true, input.value, nil, nil) when ->(inp) { inp.respond_to?(:success?) } ::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil) else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]") end end |
.Outcome!(input) ⇒ Object
102 103 104 105 106 |
# File 'lib/dry/mutations/extensions/outcome.rb', line 102 def self.Outcome! input Outcome(input).tap do |outcome| fail ::Mutations::ValidationException.new(outcome.errors) unless outcome.success? end.value end |