Class: Canvas::Validator::BlockSchema
- Inherits:
-
Object
- Object
- Canvas::Validator::BlockSchema
- Defined in:
- lib/canvas/validators/block_schema.rb
Overview
:documented: This class is used to validate a schema for a block. Example of a valid block schema: {
"attributes" => {
"my_title" => {
"type" => "string"
},
"my_color" => {
"type" => "color",
"label" => "My color",
"hint" => "Select your favourite color"
}
},
"layout" => [
{
"type" => "tab",
"label" => "Content",
"elements" => [
"my_title",
"my_color"
]
}
]
}
Constant Summary collapse
- PERMITTED_KEYS =
%w[attributes layout].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:, custom_types: []) ⇒ BlockSchema
constructor
A new instance of BlockSchema.
- #validate ⇒ Object
Constructor Details
#initialize(schema:, custom_types: []) ⇒ BlockSchema
Returns a new instance of BlockSchema.
40 41 42 43 44 |
# File 'lib/canvas/validators/block_schema.rb', line 40 def initialize(schema:, custom_types: []) @schema = normalize_schema(schema) @custom_types = custom_types @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
36 37 38 |
# File 'lib/canvas/validators/block_schema.rb', line 36 def errors @errors end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
36 37 38 |
# File 'lib/canvas/validators/block_schema.rb', line 36 def schema @schema end |
Instance Method Details
#validate ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/canvas/validators/block_schema.rb', line 46 def validate @errors = [] if ensure_valid_format ensure_no_unrecognized_keys ensure_layout_is_valid ensure_attributes_are_valid end @errors.empty? end |