class Hashema::Map::Comparison
Private Instance Methods
expected_class()
click to toggle source
# File lib/hashema/schema.rb, line 90 def expected_class raise NotImplementedError.new "#{self.class.name} must implement expected_class" end
extra_keys()
click to toggle source
# File lib/hashema/schema.rb, line 124 def extra_keys raise NotImplementedError.new "#{self.class.name} must implement extra_keys" end
fetch(key, from_map)
click to toggle source
# File lib/hashema/schema.rb, line 136 def fetch(key, from_map) raise NotImplementedError.new "#{self.class.name} must implement fetch" end
find_mismatches()
click to toggle source
# File lib/hashema/schema.rb, line 79 def find_mismatches type_mismatch || (keyset_mismatches + value_mismatches) end
keyset_mismatches()
click to toggle source
# File lib/hashema/schema.rb, line 104 def keyset_mismatches if extra_keys.empty? && missing_keys.empty? [] else missing_keys_expectation = missing_keys.any? ? "\nmissing keys were:\n\t#{missing_keys.map(&:inspect).join("\n\t")}" : '' extra_keys_expectation = extra_keys.any? ? "\nextra keys were:\n\t#{extra_keys.map(&:inspect).join("\n\t")}" : '' expectation = "have a different set of keys" + missing_keys_expectation + extra_keys_expectation [Mismatch.new(actual, expected, [], expectation)] end end
matching_keys()
click to toggle source
# File lib/hashema/schema.rb, line 132 def matching_keys raise NotImplementedError.new "#{self.class.name} must implement matching_keys" end
missing_keys()
click to toggle source
# File lib/hashema/schema.rb, line 128 def missing_keys raise NotImplementedError.new "#{self.class.name} must implement missing_keys" end
type_mismatch()
click to toggle source
# File lib/hashema/schema.rb, line 83 def type_mismatch expectation = "be a #{expected_class}, but got #{actual.class}" actual.is_a?(expected_class) ? nil : [Mismatch.new(actual, expected_class, [], expectation)] end
value_mismatches()
click to toggle source
# File lib/hashema/schema.rb, line 94 def value_mismatches matching_keys.flat_map do |key| comparison = fetch(key, expected).compare(fetch(key, actual)) comparison.mismatches.map do |mismatch| Mismatch.at key, mismatch end end end