Class: FileuidValidator
- Inherits:
 - 
      ActiveModel::EachValidator
      
        
- Object
 - ActiveModel::EachValidator
 - FileuidValidator
 
 
- Defined in:
 - app/validators/fileuid_validator.rb
 
Instance Method Summary collapse
- #match_regexp?(record, attribute, value) ⇒ Boolean
 - #validate_each(record, attribute, value) ⇒ Object
 
Instance Method Details
#match_regexp?(record, attribute, value) ⇒ Boolean
      11 12 13 14 15 16 17 18  | 
    
      # File 'app/validators/fileuid_validator.rb', line 11 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  | 
  
#validate_each(record, attribute, value) ⇒ Object
      2 3 4 5 6 7 8 9  | 
    
      # File 'app/validators/fileuid_validator.rb', line 2 def validate_each(record, attribute, value) return if [:allow_nil] && value.presence.nil? if value.is_a?(EgovUtils::Fileuid) record.errors.add(attribute, ([:message] || :fileuid_format)) if value.invalid? elsif !match_regexp?(record, attribute, value) record.errors.add(attribute, ([:message] || :fileuid_format)) end end  |