Skip to content

Instantly share code, notes, and snippets.

@igor-alexandrov
Last active July 19, 2019 03:13
Show Gist options
  • Save igor-alexandrov/a129f51d44a207431410ed91d9780907 to your computer and use it in GitHub Desktop.
Save igor-alexandrov/a129f51d44a207431410ed91d9780907 to your computer and use it in GitHub Desktop.
dry-validation conditional validation
class Fund::CreateCallForm < BaseForm
property :type
property :fund
validation do
required(:type) { filled? & included_in?(TRANSACTION_TYPES['Fund::Call']) }
end
validation if: -> (results) { rebalance? } do
required(:fund).filled
end
def rebalance?
self.type == 'rebalance'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment