class CustomDependenciesAttribute

Public Class Methods

accept_value?(value) click to toggle source
# 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 = {}) click to toggle source
# File lib/snowly/extensions/custom_dependencies.rb, line 17
def self.validate(current_schema, data, fragments, processor, validator, options = {})
  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, options)
      end
    when Hash
      validate_dependency(current_schema, data, property, dependency_value, fragments, processor, self, options)
    end
  end
end
validate_dependency(schema, data, property, dependency_hash, fragments, processor, attribute, options) click to toggle source
# File lib/snowly/extensions/custom_dependencies.rb, line 32
def self.validate_dependency(schema, data, property, dependency_hash, fragments, processor, attribute, options)
  key, value = Array(dependency_hash).flatten
  return unless data[key.to_s] == value.to_s
  return if data.has_key?(property.to_s) && not(data[property.to_s].blank?)
  message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}' when property '#{key}' is '#{value}'"
  validation_error(processor, message, fragments, schema, attribute, options[:record_errors])
end