Sha256: 106c3dce4f1ce5474f21d7f9356cefae713035bbcfe3f0ff33d94e5519a68050
Contents?: true
Size: 630 Bytes
Versions: 43
Compression:
Stored size: 630 Bytes
Contents
# frozen_string_literal: true require_relative 'validator_builder' module MyConcern extend ActiveSupport::Concern class_methods do def validate(*fields, expected_class) builder = ::ValidationBuilder.new(self, expected: expected_class) validatable_fields.concat(fields) builder.add_accessors(fields) fields.each do |field| builder.add_validation(field) end builder.build end def validatable_fields @validatable_fields ||= [] end end def valid? self.class.validatable_fields.all? do |field| public_send("#{field}_valid?") end end end
Version data entries
43 entries across 43 versions & 1 rubygems