Class: Canvas::Validator::CustomType
- Inherits:
-
Object
- Object
- Canvas::Validator::CustomType
- Defined in:
- lib/canvas/validators/custom_type.rb
Overview
:documented: This class is used to validate the JSON defining a custom type.
An example of a valid custom type: {
"key": "faq",
"name": "Faq",
"attributes": [
{
"name": "question",
"label": "Question",
"type": "string"
},
{
"name": "answer",
"label": "Answer",
"type": "text"
}
]
}
Constant Summary collapse
- REQUIRED_KEYS =
%w[key name attributes].freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema:) ⇒ CustomType
constructor
A new instance of CustomType.
- #validate ⇒ Object
Constructor Details
#initialize(schema:) ⇒ CustomType
Returns a new instance of CustomType.
31 32 33 34 |
# File 'lib/canvas/validators/custom_type.rb', line 31 def initialize(schema:) @schema = schema @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
29 30 31 |
# File 'lib/canvas/validators/custom_type.rb', line 29 def errors @errors end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
29 30 31 |
# File 'lib/canvas/validators/custom_type.rb', line 29 def schema @schema end |
Instance Method Details
#validate ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/canvas/validators/custom_type.rb', line 36 def validate ensure_valid_format && ensure_has_required_keys && ensure_no_unrecognized_keys && ensure_keys_are_correct_types && ensure_key_is_lowercase && ensure_key_value_is_not_reserved && ensure_no_duplicate_attributes && ensure_attributes_are_valid && ensure_first_attribute_not_array errors.empty? end |