Created
March 13, 2016 14:23
-
-
Save KamilLelonek/9839a3a689a6d30a8a60 to your computer and use it in GitHub Desktop.
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
class ValidateSumOfMilliliters | |
def call(form_object:) | |
find_juice_by_id.(form_object.juice_id) | |
.and_then { |juice| validate_sum_of_milliliters(juice: juice) } | |
.or_else { |error| fail_with_invalid_juice_id(error) } | |
end | |
private | |
def fail_with_invalid_juice_id(error) | |
interrupt( | |
:invalid_attributes, | |
juice_id: "Juice with id #{error.juice_id} doesn't exist!" | |
) | |
end | |
def find_juice_by_id | |
Juices::Queries::ById.new(juice_repository) | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment