Class: Idcf::Cli::Validate::Custom::RequireRelationValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/idcf/cli/validate/custom/require_relation_validator.rb

Overview

require relation validator

Constant Summary collapse

MESSAGES =
{
  message: 'A related parameter isn\'t input. (%<msg>s)'
}.freeze

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/idcf/cli/validate/custom/require_relation_validator.rb', line 13

def validate(record)
  return unless process?(record)

  nones = make_nones(record)
  return if nones.empty?

  msg = format(MESSAGES[:message], msg: nones.join('/'))
  record.errors.add(nones.first, msg, **{})
end