Sha256: 50d6885d789525d682a0df563a3ef5b7a2a4f1b2078ef4331053ed5a4e9e3fa7

Contents?: true

Size: 668 Bytes

Versions: 102

Compression:

Stored size: 668 Bytes

Contents

class FileuidValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if options[:allow_nil] && value.presence.nil?
    if value.is_a?(EgovUtils::Fileuid)
      record.errors.add(attribute, (options[:message] || :fileuid_format)) if value.invalid?
    elsif !match_regexp?(record, attribute, value)
      record.errors.add(attribute, (options[:message] || :fileuid_format))
    end
  end

  def match_regexp?(record, attribute, value)
    type = nil
    if type
      value =~ EgovUtils::Fileuid::TYPES[type].to_regex
    else
      EgovUtils::Fileuid::TYPES.values.any?{|type_def| value =~ type_def.to_regex }
    end
  end
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
egov_utils-1.5.0.alpha16 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha15 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha14 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha13 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha12 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha11 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha10 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha9 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha8 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha7 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha6 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha5 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha4 app/validators/fileuid_validator.rb
egov_utils-1.4.5 app/validators/fileuid_validator.rb
egov_utils-1.4.4 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha3 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha2 app/validators/fileuid_validator.rb
egov_utils-1.5.0.alpha1 app/validators/fileuid_validator.rb
egov_utils-1.4.3 app/validators/fileuid_validator.rb
egov_utils-1.4.2 app/validators/fileuid_validator.rb