Class: Canvas::Validator::SchemaAttribute
- Inherits:
-
Object
- Object
- Canvas::Validator::SchemaAttribute
- Defined in:
- lib/canvas/validators/schema_attribute.rb,
lib/canvas/validators/schema_attributes/base.rb,
lib/canvas/validators/schema_attributes/date.rb,
lib/canvas/validators/schema_attributes/link.rb,
lib/canvas/validators/schema_attributes/page.rb,
lib/canvas/validators/schema_attributes/post.rb,
lib/canvas/validators/schema_attributes/color.rb,
lib/canvas/validators/schema_attributes/image.rb,
lib/canvas/validators/schema_attributes/radio.rb,
lib/canvas/validators/schema_attributes/range.rb,
lib/canvas/validators/schema_attributes/number.rb,
lib/canvas/validators/schema_attributes/select.rb,
lib/canvas/validators/schema_attributes/package.rb,
lib/canvas/validators/schema_attributes/product.rb,
lib/canvas/validators/schema_attributes/variant.rb,
lib/canvas/validators/schema_attributes/enquiry_form.rb,
lib/canvas/validators/schema_attributes/experience_date.rb,
lib/canvas/validators/schema_attributes/experience_slot.rb
Overview
:documented: This class can be used to validate the format of an attribute that is used within a schema.
Example:
"name" => "headings",
"type" => "string",
"default" => "My Heading",
"array" => true
Defined Under Namespace
Classes: Base, Color, Date, EnquiryForm, ExperienceDate, ExperienceSlot, Image, Link, Number, Package, Page, Post, Product, Radio, Range, Select, Variant
Constant Summary collapse
- VALIDATORS =
{ "image" => SchemaAttribute::Image, "product" => SchemaAttribute::Product, "post" => SchemaAttribute::Post, "page" => SchemaAttribute::Page, "link" => SchemaAttribute::Link, "text" => SchemaAttribute::Base, "string" => SchemaAttribute::Base, "boolean" => SchemaAttribute::Base, "number" => SchemaAttribute::Number, "color" => SchemaAttribute::Color, "select" => SchemaAttribute::Select, "range" => SchemaAttribute::Range, "radio" => SchemaAttribute::Radio, "variant" => SchemaAttribute::Variant, "package" => SchemaAttribute::Package, "date" => SchemaAttribute::Date, "experience_date" => SchemaAttribute::ExperienceDate, "experience_slot" => SchemaAttribute::ExperienceSlot, "enquiry_form" => SchemaAttribute::EnquiryForm, }.freeze
- RESERVED_NAMES =
%w[ page company cart flash block ].freeze
Instance Attribute Summary collapse
-
#additional_reserved_names ⇒ Object
readonly
Returns the value of attribute additional_reserved_names.
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#custom_types ⇒ Object
readonly
Returns the value of attribute custom_types.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(attribute:, custom_types: [], additional_reserved_names: []) ⇒ SchemaAttribute
constructor
A new instance of SchemaAttribute.
- #validate ⇒ Object
Constructor Details
#initialize(attribute:, custom_types: [], additional_reserved_names: []) ⇒ SchemaAttribute
Returns a new instance of SchemaAttribute.
52 53 54 55 56 57 |
# File 'lib/canvas/validators/schema_attribute.rb', line 52 def initialize(attribute:, custom_types: [], additional_reserved_names: []) @attribute = attribute @custom_types = custom_types @errors = [] @additional_reserved_names = additional_reserved_names end |
Instance Attribute Details
#additional_reserved_names ⇒ Object (readonly)
Returns the value of attribute additional_reserved_names.
50 51 52 |
# File 'lib/canvas/validators/schema_attribute.rb', line 50 def additional_reserved_names @additional_reserved_names end |
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
50 51 52 |
# File 'lib/canvas/validators/schema_attribute.rb', line 50 def attribute @attribute end |
#custom_types ⇒ Object (readonly)
Returns the value of attribute custom_types.
50 51 52 |
# File 'lib/canvas/validators/schema_attribute.rb', line 50 def custom_types @custom_types end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
50 51 52 |
# File 'lib/canvas/validators/schema_attribute.rb', line 50 def errors @errors end |
Instance Method Details
#validate ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/canvas/validators/schema_attribute.rb', line 59 def validate ensure_attribute_is_hash && ensure_not_reserved_name && ensure_not_boolean_array && ensure_not_radio_array && ensure_type_key_is_present && ensure_valid_for_type && ensure_composite_array_without_non_array_attributes errors.empty? end |