-
-
Save jak/f44dc6b9cb97c33a8cb2d684e1d9c162 to your computer and use it in GitHub Desktop.
Pseudo code
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
## Promocode controller/generate endpoint controller | |
def generate | |
if not @promocode.is_valid? | |
#An array of errors | |
render json: @promocode.errors | |
end | |
if @promocode.save | |
blah | |
end | |
end | |
## Promocode model | |
def is_valid? | |
# I wan't to map over the constraints and run their validate function which should either return nil or throw a | |
# ConstraintError, but I want this method to swallow that throw and append it to an array of errors | |
# and then throw those errors up. But I don't really know how to do that. | |
errors = [] | |
# this will end up being a multidimensional array of errors.... because i'm lazy | |
errors = self.promotion.constraints.map { |con| con.validate } | |
return errors | |
end | |
## A constraint | |
class Constraint | |
def validate | |
# if some criteria isn't met, throw a Constraint error | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment