Class: Jsonschema::Matchers::MatchJsonschema
- Inherits:
-
Object
- Object
- Jsonschema::Matchers::MatchJsonschema
- Defined in:
- lib/jsonschema/matchers/match_jsonschema.rb
Overview
Match Jsonschema snapshot
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(metadata, name) ⇒ MatchJsonschema
constructor
A new instance of MatchJsonschema.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(metadata, name) ⇒ MatchJsonschema
Returns a new instance of MatchJsonschema.
11 12 13 14 15 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 11 def initialize(, name) @metadata = @path = "#{root_dir}/#{Metadater.call()}" @name = name.downcase.gsub(%r{[\/\s]}, '/' => '_', ' ' => '_') end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9 def errors @errors end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9 def path @path end |
Instance Method Details
#failure_message ⇒ Object
26 27 28 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 26 def errors.join("\n") end |
#matches?(actual) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 17 def matches?(actual) file_full_path = "#{path}/#{name}.json" record(actual) unless File.exist?(file_full_path) file = File.open(file_full_path) @errors = JSON::Validator.fully_validate(file.path, actual) errors.empty? end |