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.4.1 app/validators/fileuid_validator.rb
egov_utils-1.4.0 app/validators/fileuid_validator.rb
egov_utils-1.3.0 app/validators/fileuid_validator.rb
egov_utils-1.2.4 app/validators/fileuid_validator.rb
egov_utils-1.2.3 app/validators/fileuid_validator.rb
egov_utils-1.2.2 app/validators/fileuid_validator.rb
egov_utils-1.2.1 app/validators/fileuid_validator.rb
egov_utils-1.2.0 app/validators/fileuid_validator.rb
egov_utils-1.1.1 app/validators/fileuid_validator.rb
egov_utils-1.1.0 app/validators/fileuid_validator.rb
egov_utils-1.0.3 app/validators/fileuid_validator.rb
egov_utils-1.0.2 app/validators/fileuid_validator.rb
egov_utils-1.0.1 app/validators/fileuid_validator.rb
egov_utils-1.0.0 app/validators/fileuid_validator.rb
egov_utils-0.7.5 app/validators/fileuid_validator.rb
egov_utils-0.7.4 app/validators/fileuid_validator.rb
egov_utils-0.7.3 app/validators/fileuid_validator.rb
egov_utils-0.7.2 app/validators/fileuid_validator.rb
egov_utils-0.7.1 app/validators/fileuid_validator.rb
egov_utils-0.7.0 app/validators/fileuid_validator.rb