Class: Hoodoo::Presenters::UUID
- Defined in:
- lib/hoodoo/presenters/types/uuid.rb
Overview
A JSON UUID schema member.
Instance Attribute Summary collapse
-
#resource ⇒ Object
The optional associated resource kind, as a symbol (e.g. ‘:Product’).
Attributes inherited from Field
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ UUID
constructor
Initialize a UUID instance with the appropriate name and options.
-
#validate(data, path = '') ⇒ Object
Check if data is a valid UUID and return a Hoodoo::Errors instance.
Methods inherited from Field
#full_path, #has_default?, #render, #walk
Constructor Details
#initialize(name, options = {}) ⇒ UUID
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.
31 32 33 34 |
# File 'lib/hoodoo/presenters/types/uuid.rb', line 31 def initialize( name, = {} ) @resource = .delete( :resource ) super name, end |
Instance Attribute Details
#resource ⇒ Object
The optional associated resource kind, as a symbol (e.g. ‘:Product’).
24 25 26 |
# File 'lib/hoodoo/presenters/types/uuid.rb', line 24 def resource @resource end |
Instance Method Details
#validate(data, path = '') ⇒ Object
Check if data is a valid UUID and return a Hoodoo::Errors instance.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |