Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro::Case contracts #22

Open
serradura opened this issue May 1, 2020 · 0 comments
Open

Micro::Case contracts #22

serradura opened this issue May 1, 2020 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@serradura
Copy link
Owner

serradura commented May 1, 2020

Micro::Case contracts

class Divide < Micro::Case
  attributes :a, :b

  results do |on|
    on.failure(:attributes_must_be_numbers)
    on.failure(:division_by_zero)

    on.success(result: [:division])
  end

  def call!
    return Failure(:attributes_must_be_numbers) unless Kind.of?(Numeric, a, b)

    return Failure(:division_by_zero) if b == 0

    Success result: { division: a / b }
  end
end
@serradura serradura added the enhancement New feature or request label May 1, 2020
@serradura serradura added this to the 3.0.0 milestone May 1, 2020
@serradura serradura changed the title Micro::Case flow contracts Micro::Case::Flow contracts May 1, 2020
@serradura serradura changed the title Micro::Case::Flow contracts Micro::Case contracts May 1, 2020
@serradura serradura modified the milestones: 3.0.0, 3.x May 2, 2020
@serradura serradura modified the milestones: 3.x, 4.x Aug 21, 2020
@serradura serradura modified the milestones: 4.x, Ideas Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant