Class: CustomDependenciesAttribute
- Inherits:
-
JSON::Schema::Attribute
- Object
- JSON::Schema::Attribute
- CustomDependenciesAttribute
- Defined in:
- lib/snowly/extensions/custom_dependencies.rb
Class Method Summary collapse
- .accept_value?(value) ⇒ Boolean
- .validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
- .validate_dependency(schema, data, property, dependency_hash, fragments, processor, attribute, options) ⇒ Object
Class Method Details
.accept_value?(value) ⇒ Boolean
40 41 42 |
# File 'lib/snowly/extensions/custom_dependencies.rb', line 40 def self.accept_value?(value) value.is_a?(Array) || value.is_a?(Hash) end |
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/snowly/extensions/custom_dependencies.rb', line 17 def self.validate(current_schema, data, fragments, processor, validator, = {}) return unless data.is_a?(Hash) current_schema.schema['custom_dependencies'].each do |property, dependency_value| next unless accept_value?(dependency_value) case dependency_value when Array dependency_value.each do |dependency_hash| validate_dependency(current_schema, data, property, dependency_hash, fragments, processor, self, ) end when Hash validate_dependency(current_schema, data, property, dependency_value, fragments, processor, self, ) end end end |
.validate_dependency(schema, data, property, dependency_hash, fragments, processor, attribute, options) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/snowly/extensions/custom_dependencies.rb', line 32 def self.validate_dependency(schema, data, property, dependency_hash, fragments, processor, attribute, ) key, value = Array(dependency_hash).flatten return unless data[key.to_s] == value.to_s return if data.has_key?(property.to_s) = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}' when property '#{key}' is '#{value}'" validation_error(processor, , fragments, schema, attribute, [:record_errors]) end |