-
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.
contracts: implement a couple of example integrations
- Loading branch information
1 parent
72585a0
commit 9c69e75
Showing
7 changed files
with
227 additions
and
0 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
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/inline" | ||
|
||
gemfile true do | ||
source "https://rubygems.org" | ||
|
||
gem "activemodel" | ||
gem "i_do_not_need_interactor", github: "alessandro-fazzi/i_do_not_need_interactor" | ||
gem "amazing_print" | ||
end | ||
|
||
require "active_model" | ||
require "amazing_print" | ||
|
||
class DoSomething # rubocop:disable Style/Documentation | ||
include Interactor | ||
include Interactor::Contract::ActiveModel | ||
|
||
def call(ctx) | ||
ctx[:done] = true | ||
end | ||
|
||
contract do | ||
attribute :done, :boolean | ||
attribute :foo, :string | ||
validates :foo, presence: true | ||
end | ||
end | ||
|
||
result = DoSomething.call | ||
if result.success? | ||
ap result | ||
else | ||
ap result.errors | ||
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/inline" | ||
|
||
gemfile true do | ||
source "https://rubygems.org" | ||
|
||
gem "dry-validation" | ||
gem "i_do_not_need_interactor", github: "alessandro-fazzi/i_do_not_need_interactor" | ||
gem "amazing_print" | ||
end | ||
|
||
require "dry-validation" | ||
require "amazing_print" | ||
|
||
class DoSomething # rubocop:disable Style/Documentation | ||
include Interactor | ||
include Interactor::Contract::DryValidation | ||
|
||
def call(ctx) | ||
ctx[:done] = true | ||
end | ||
|
||
contract do | ||
params do | ||
optional(:done).value(:bool) | ||
required(:foo).value(:string) | ||
end | ||
end | ||
end | ||
|
||
result = DoSomething.call(done: false) | ||
if result.success? | ||
ap result | ||
else | ||
ap result.errors | ||
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
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 |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
require "i_do_not_need_interactor" | ||
|
||
require "minitest/autorun" | ||
|
||
require "active_model" | ||
|
||
require "dry-validation" |
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