Sha256: 5127b29bde68039826e5db96190284bc1498ffbdf1ba2eb105de9f7717c9e46c
Contents?: true
Size: 840 Bytes
Versions: 9
Compression:
Stored size: 840 Bytes
Contents
# frozen_string_literal: true # A custom validator to make sure components are correctly assigned to a model. # # Adds a presence validation and checks that the manifest is the correct one. class ComponentValidator < ActiveModel::EachValidator # Validates the arguments passed to the validator. def check_validity! raise ArgumentError, "You must include a `manifest` option with the name of the manifest to validate when validating a component" if options[:manifest].blank? end # The actual validator method. It is called when ActiveRecord iterates # over all the validators. def validate_each(record, attribute, component) unless component record.errors.add(attribute, :blank) return end record.errors.add(attribute, :invalid) if component.manifest_name.to_s != options[:manifest].to_s end end
Version data entries
9 entries across 9 versions & 1 rubygems