Skip to content

Instantly share code, notes, and snippets.

@davydovanton
Created October 11, 2017 10:21
Show Gist options
  • Save davydovanton/d8e9bd390b2f2e496a49011a7be32913 to your computer and use it in GitHub Desktop.
Save davydovanton/d8e9bd390b2f2e496a49011a7be32913 to your computer and use it in GitHub Desktop.
class Service
include Dry::Matcher.for(:call, with: Dry::Matcher::EitherMatcher)
include Dry::Monads::Either::Mixin
def call(payload)
# ...
Right(payload)
end
end
Servise.new.call({ ... }) do |m|
m.success do |payload|
# ...
end
m.failed do |payload|
# ...
end
end
# когда вся логика на месте и понятно как и на какие шаги разделить объект
class Service
include Dry::Transaction
step :step1
# ...
def step1(payload)
# ...
Right(payload)
end
end
Servise.new.call({ ... }) do |m|
m.success do |payload|
# ...
end
m.failed do |payload|
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment