Class: Hoodoo::Presenters::Text

Inherits:
Field
  • Object
show all
Defined in:
lib/hoodoo/presenters/types/text.rb

Overview

A JSON String schema member - unlimited length String.

Direct Known Subclasses

Tags

Instance Attribute Summary

Attributes inherited from Field

#default, #name, #required

Instance Method Summary collapse

Methods inherited from Field

#full_path, #has_default?, #initialize, #render, #walk

Constructor Details

This class inherits a constructor from Hoodoo::Presenters::Field

Instance Method Details

#validate(data, path = '') ⇒ Object

Check if data is a valid String and return a Hoodoo::Errors instance.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hoodoo/presenters/types/text.rb', line 10

def validate( data, path = '' )
  errors = super( data, path )
  return errors if errors.has_errors? || ( ! @required && data.nil? )

  unless data.is_a?( ::String )
    errors.add_error(
      'generic.invalid_string',
      :message   => "Field `#{ full_path( path ) }` is an invalid string",
      :reference => { :field_name => full_path( path ) }
    )
  end

  errors
end