Class: Canvas::Validator::MenuSchema
- Inherits:
-
Object
- Object
- Canvas::Validator::MenuSchema
- Defined in:
- lib/canvas/validators/menu_schema.rb
Overview
:documented: This class is used to validate a schema for a menu.
Example: { "max_item_levels" => 2, "supports_open_new_tab" => "true", "attributes" => { "fixed" => { "group" => "design", "label" => "Fixed when scrolling", "hint" => "The menu will stay fixed to the top when scrolling down the page.", "type" => "boolean", "default" => "false" }, "background_color" => { "type" => "color" } }, "layout" => [ { "type" => "tab", "label" => "Content", "elements" => [ "fixed", "background_color" ] } ] }
Direct Known Subclasses
Constant Summary collapse
- PERMITTED_KEYS =
%w[cache max_item_levels supports_open_new_tab attributes layout].freeze
- ADDITIONAL_RESERVED_NAMES =
%w[items type].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: []) ⇒ MenuSchema
constructor
A new instance of MenuSchema.
- #validate ⇒ Object
Constructor Details
#initialize(schema:, custom_types: []) ⇒ MenuSchema
Returns a new instance of MenuSchema.
43 44 45 46 47 |
# File 'lib/canvas/validators/menu_schema.rb', line 43 def initialize(schema:, custom_types: []) @schema = schema @custom_types = custom_types @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
39 40 41 |
# File 'lib/canvas/validators/menu_schema.rb', line 39 def errors @errors end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
39 40 41 |
# File 'lib/canvas/validators/menu_schema.rb', line 39 def schema @schema end |
Instance Method Details
#validate ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/canvas/validators/menu_schema.rb', line 49 def validate if ensure_valid_format ensure_no_unrecognized_keys ensure_cache_is_valid ensure_max_item_levels_is_valid ensure_layout_is_valid ensure_attributes_are_valid end @errors.empty? end |