Class: Moku6::Rules::ExampleConsistencyRule
- Defined in:
- lib/moku6/rules/example_consistency_rule.rb
Instance Method Summary collapse
-
#check(event) ⇒ Object
: (Event event) -> Array.
Methods inherited from BaseRule
Constructor Details
This class inherits a constructor from Moku6::Rules::BaseRule
Instance Method Details
#check(event) ⇒ Object
: (Event event) -> Array
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/moku6/rules/example_consistency_rule.rb', line 10 def check(event) examples = collect_examples(event) return [] if examples.empty? schemer = Senko.compile(EnvelopeSchema.for(event)) examples.each_with_index.flat_map do |example, idx| result = schemer.validate(example) next [] if result.valid? result.errors.map do |err| h = err.to_h location = h["instanceLocation"].to_s pointer = location.empty? ? "(root)" : location keyword = h["keywordLocation"].to_s.split("/").last offense(event, :error, "examples[#{idx}] does not match the definition #{pointer}: #{keyword}", rule: "example_consistency") end end end |