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
-
#custom_types ⇒ Object
readonly
Returns the value of attribute custom_types.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema:, custom_types: []) ⇒ CustomType
constructor
A new instance of CustomType.
- #validate ⇒ Object
Constructor Details
#initialize(schema:, custom_types: []) ⇒ CustomType
Returns a new instance of CustomType.
31 32 33 34 35 |
# File 'lib/canvas/validators/custom_type.rb', line 31 def initialize(schema:, custom_types: []) @schema = schema @custom_types = custom_types @errors = [] end |
Instance Attribute Details
#custom_types ⇒ Object (readonly)
Returns the value of attribute custom_types.
29 30 31 |
# File 'lib/canvas/validators/custom_type.rb', line 29 def custom_types @custom_types end |
#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
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/canvas/validators/custom_type.rb', line 37 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 |