Sha256: 6f22228dabdaca7069918963b7357078501646c578b22952b3266e33cb7c8580

Contents?: true

Size: 411 Bytes

Versions: 3

Compression:

Stored size: 411 Bytes

Contents

module Volt
  class PresenceValidator
    def self.validate(model, field_name, args)
      errors = {}
      value  = model.read_attribute(field_name)
      if !value || value.blank?
        if args.is_a?(Hash) && args[:message]
          message = args[:message]
        else
          message = 'must be specified'
        end

        errors[field_name] = [message]
      end

      errors
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.8.21 lib/volt/models/validators/presence_validator.rb
volt-0.8.20 lib/volt/models/validators/presence_validator.rb
volt-0.8.19 lib/volt/models/validators/presence_validator.rb