Last active
August 25, 2020 19:00
-
-
Save serradura/eb0dbf5ff1832a3773278a342735e714 to your computer and use it in GitHub Desktop.
u-case ideas - Skip e Chech
This file contains hidden or 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
module ContractTemplates | |
module Update | |
class TryCreateRevision < Micro::Case | |
attributes :company, :params | |
def call! | |
return Success(:skipped_contract_revision) unless term_changed? | |
ContractRevision.create!(contract_revision_params) | |
Success(:contract_revision_was_created) | |
end | |
private | |
def term_changed?; end | |
def contract_revision_params; end | |
end | |
end | |
end | |
# -- | |
module ContractTemplates | |
module Update | |
class TryCreateRevision < Micro::Case | |
attributes :company, :params | |
def call! | |
Skip if: !term_changed?, or: apply(:create_contract_revision) | |
end | |
private | |
def term_changed?; end | |
def contract_revision_params; end | |
def create_contract_revision | |
ContractRevision.create!(contract_revision_params) | |
Success(:contract_revision_was_created) | |
end | |
end | |
end | |
end |
class User::Registration < Micro::Case
attributes :email, :password
def call!
Skip(if: user_already_exist?, or: apply(:create_user))
.then(apply(:log))
end
end
class User::Registration < Micro::Case
attributes :email, :password
def call!
Skip(if: user_already_exist?, or: ::User::Create)
.then(apply(:log))
end
end
class User::Registration < Micro::Case
attributes :email, :password
def call!
Skip(if: user_already_exist?, or: apply(:create_user))
.then(apply(:log))
end
end
class User::Registration < Micro::Case
attributes :email, :password
def call!
Check(:email, result: email_already_exist?)
.then(apply(:create_user))
.then(apply(:log))
end
end
Check
class User::Registration < Micro::Case
attributes :email, :password
def call!
Check(:email, result: email_already_exist?)
.or(apply(:create_user))
.then(apply(:log))
end
end
class User::Registration < Micro::Case
attributes :email, :password
def call!
Check(:email, result: email_already_exist?)
.then(apply(:create_user))
.then(apply(:log))
end
end
Try
class User::Registration < Micro::Case
attributes :email, :password
def call!
Try(result: { user: -> { User.create!(attributes) } })
.then(apply(:log))
end
end
class User::Registration < Micro::Case
attributes :email, :password
def call!
Try(result: { user: apply(:create_user) })
.or(apply(:log))
end
def create_user; User.create!(attributes); end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We could add an
or
method on Results. It's basically then, but for failures.