Sha256: e8368cef0fe0ee85072c7f43f61435397be172db845f805c89f15074dc4a6124
Contents?: true
Size: 599 Bytes
Versions: 3
Compression:
Stored size: 599 Bytes
Contents
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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sinclair-1.1.1 | spec/support/models/my_concern.rb |
sinclair-1.1.0 | spec/support/models/my_concern.rb |
sinclair-1.0.0 | spec/support/models/my_concern.rb |