-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use cases to work with do notation
- Loading branch information
1 parent
a5f9a4c
commit a9677a0
Showing
6 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dry/validation" | ||
require "dry/validation/contract" | ||
|
||
module UseCases | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module UseCases | ||
VERSION = "3.0.1" | ||
VERSION = "3.0.2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class OperationCallingUseCase | ||
include Dry::Monads[:result] | ||
include Dry::Monads::Do.for(:call) | ||
|
||
def call | ||
result = yield call_operation | ||
Success(result) | ||
end | ||
|
||
private | ||
|
||
def call_operation | ||
operation = Operation.new | ||
operation.call({}) | ||
end | ||
end | ||
|
||
# Path: spec/use_cases/steps/operation.rb | ||
class Operation | ||
include UseCase | ||
|
||
step :step_1 | ||
|
||
def step_1 | ||
Success(:step_1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe UseCases::Result do | ||
describe 'self' do | ||
context 'when used by a service using the do notation' do | ||
let(:caller) do | ||
require 'support/test_subjects/operation_calling_use_case' | ||
OperationCallingUseCase.new | ||
end | ||
|
||
it 'works' do | ||
expect(caller.call).to be_success | ||
end | ||
end | ||
end | ||
end |