class UuidValidator

Provides simple UUID validation via an ActiveModel::EachValidator. Uuid is not capitalised as ActiveModel’s “magic” cannot find the validator if it is.

Public Instance Methods

validate_each( record, attribute, value ) click to toggle source

Any field this validator is applied to is considered valid if it is nil or a valid UUID. In the case of UUIDs which should not be nil, a separate validation must be added.

Example:

class SomeModel < ActiveRecord::Base
  validates :somefield, uuid: true
end
# File lib/hoodoo/active/active_model/uuid_validator.rb, line 32
def validate_each( record, attribute, value )
  unless value.nil? || Hoodoo::UUID.valid?( value )
    record.errors.add(attribute, options[ :message ] || 'is invalid' )
  end

end