A JSON UUID schema member.
Methods
Attributes
[RW] | resource | The optional associated resource kind, as a symbol (e.g. ':Product'). |
Class Public methods
new( name, options = {} )
Link
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.
Source: show
# File lib/hoodoo/presenters/types/uuid.rb, line 31 def initialize( name, options = {} ) @resource = options.delete( :resource ) super name, options end
Instance Public methods
validate( data, path = '' )
Link
Check if data is a valid UUID and return a Hoodoo::Errors instance.
Source: show
# 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