Class: Inspector::Metadata::Walker
- Inherits:
-
Object
- Object
- Inspector::Metadata::Walker
- Defined in:
- lib/inspector/metadata/walker.rb
Instance Method Summary collapse
-
#initialize(violation_list_class, validator_map) ⇒ Walker
constructor
A new instance of Walker.
- #walk_object(metadata, object) ⇒ Object
Constructor Details
#initialize(violation_list_class, validator_map) ⇒ Walker
Returns a new instance of Walker.
4 5 6 7 |
# File 'lib/inspector/metadata/walker.rb', line 4 def initialize(violation_list_class, validator_map) @violation_list_class = violation_list_class @validator_map = validator_map end |
Instance Method Details
#walk_object(metadata, object) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inspector/metadata/walker.rb', line 9 def walk_object(, object) violations = @violation_list_class.new .constraints.each do |constraint| not_found = "validator #{constraint.validator} cannot be found" validator = @validator_map.fetch(constraint.validator) { raise not_found } validator.validate(object, constraint, violations) end # walk object attributes, properties and children if object constraints passed if violations.empty? ..each do || path = .attribute_name value = .attribute_value(object) violations[path] = walk_object(, value) end ..each do || path = "[#{.property_name}]" value = .property_value(object) violations[path] = walk_object(, value) end ..children(object) do |child, index| path = "[#{index}]" violations[path] = walk_object(., child) end unless ..nil? end violations end |