class Hoodoo::Presenters::UUID
A JSON UUID
schema member.
Attributes
resource[RW]
The optional associated resource kind, as a symbol (e.g. ‘:Product’).
Public Class Methods
new( name, options = {} )
click to toggle source
Initialize a UUID
instance with the appropriate name and options.
name
-
The JSON key.
options
-
A
Hash
of options, e.g. :resource => :Product, :required => true.
Calls superclass method
Hoodoo::Presenters::Field::new
# File lib/hoodoo/presenters/types/uuid.rb, line 31 def initialize( name, options = {} ) @resource = options.delete( :resource ) super name, options end
Public Instance Methods
validate( data, path = '' )
click to toggle source
Check if data is a valid UUID
and return a Hoodoo::Errors
instance.
Calls superclass method
Hoodoo::Presenters::Field#validate
# File lib/hoodoo/presenters/types/uuid.rb, line 38 def validate( data, path = '' ) errors = super( data, path ) return errors if errors.has_errors? || ( ! @required && data.nil? ) unless Hoodoo::UUID.valid?( data ) errors.add_error( 'generic.invalid_uuid', :message => "Field `#{ full_path( path ) }` is an invalid UUID", :reference => { :field_name => full_path( path ) } ) end errors end