/usr/lib/ruby/vendor_ruby/sequel/plugins/error_splitter.rb is in ruby-sequel 4.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | module Sequel
module Plugins
# The error_splitter plugin automatically splits errors entries related to
# multiple columns to have separate error entries, one per column. For example,
# a multiple column uniqueness entry:
#
# validates_unique([:artist_id, :name])
#
# would by default result in errors entries such as:
#
# {[:artist_id, :name]=>'is already taken'}
#
# This plugin transforms those errors into:
#
# {:artist_id=>'is already taken', :name=>'is already taken'}
#
# The main reason to split errors is if you have a list of fields that you
# are checking for validation errors. If you don't split the errors, then:
#
# errors.on(:artist_id)
#
# would not return the uniqueness error.
#
# Usage:
#
# # Make all model subclass instances split errors (called before loading subclasses)
# Sequel::Model.plugin :error_splitter
#
# # Make the Album class split errors
# Album.plugin :error_splitter
module ErrorSplitter
module InstanceMethods
# If the model instance is not valid, go through all of the errors entries. For
# any that apply to multiple columns, remove them and add separate error entries,
# one per column.
def _valid?(*)
v = super
unless v
errors.keys.select{|k| k.is_a?(Array)}.each do |ks|
msgs = errors.delete(ks)
ks.each do |k|
msgs.each do |msg|
errors.add(k, msg)
end
end
end
end
v
end
end
end
end
end
|