Class: ThemeSettingsObjectValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_settings_object_validator.rb

Defined Under Namespace

Classes: ThemeSettingsObjectError, ThemeSettingsObjectErrors

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema:, object:, json_pointer_prefix: "", errors: {}, valid_ids_lookup: {}) ⇒ ThemeSettingsObjectValidator

Returns a new instance of ThemeSettingsObjectValidator.



63
64
65
66
67
68
69
70
# File 'lib/theme_settings_object_validator.rb', line 63

def initialize(schema:, object:, json_pointer_prefix: "", errors: {}, valid_ids_lookup: {})
  @object = object.with_indifferent_access
  @schema_name = schema[:name]
  @properties = schema[:properties]
  @errors = errors
  @json_pointer_prefix = json_pointer_prefix
  @valid_ids_lookup = valid_ids_lookup
end

Class Method Details

.validate_objects(schema:, objects:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/theme_settings_object_validator.rb', line 5

def validate_objects(schema:, objects:)
  error_messages = []

  objects.each_with_index do |object, index|
    humanize_error_messages(
      self.new(schema: schema, object: object).validate,
      index:,
      error_messages:,
    )
  end

  error_messages
end

Instance Method Details

#property_values_of_type(type) ⇒ Object



88
89
90
# File 'lib/theme_settings_object_validator.rb', line 88

def property_values_of_type(type)
  fetch_property_values_of_type(@properties, @object, type)
end

#validateObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/theme_settings_object_validator.rb', line 72

def validate
  @properties.each do |property_name, property_attributes|
    if property_attributes[:type] == "objects"
      validate_child_objects(
        @object[property_name],
        property_name:,
        schema: property_attributes[:schema],
      )
    else
      validate_property(property_name, property_attributes)
    end
  end

  @errors
end