Sha256: dd8623a654cfa7d116af3d79bcc73c1e3f4e8dd52411c9078cbbc73aa7e2c67c
Contents?: true
Size: 691 Bytes
Versions: 8
Compression:
Stored size: 691 Bytes
Contents
# frozen_string_literal: true module Cocina module Models # Validate upon construction module Validatable extend ActiveSupport::Concern class_methods do def new(attributes = default_attributes, safe = false, validate = true, &block) Validators::Validator.validate(self, attributes.with_indifferent_access) if validate super(attributes, safe, &block) end end def new(*args) validate = args.first.delete(:validate) if args.present? new_model = super(*args) Validators::Validator.validate(new_model.class, new_model.to_h) if validate || validate.nil? new_model end end end end
Version data entries
8 entries across 8 versions & 1 rubygems