Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created March 13, 2016 14:23
Show Gist options
  • Save KamilLelonek/9839a3a689a6d30a8a60 to your computer and use it in GitHub Desktop.
Save KamilLelonek/9839a3a689a6d30a8a60 to your computer and use it in GitHub Desktop.
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