Skip to content

Instantly share code, notes, and snippets.

@T-800
Forked from igor-alexandrov/form.rb
Created March 20, 2018 09:03
Show Gist options
  • Select an option

  • Save T-800/51d507a09f87e47db235cbbd7f6dda7a to your computer and use it in GitHub Desktop.

Select an option

Save T-800/51d507a09f87e47db235cbbd7f6dda7a 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