Class: JsonSchemaValidator::Base
- Inherits:
-
Object
- Object
- JsonSchemaValidator::Base
- Defined in:
- lib/json_schema_validator/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#files_to_validate ⇒ Array<String>
File paths.
Class Method Summary collapse
-
.run(files) ⇒ Object
Run the given validator with all schema files.
Instance Method Summary collapse
-
#errors ⇒ Array<String>
Error schemas.
-
#log ⇒ Array<String>
Test log.
-
#log_fmt ⇒ Object
Joins the logs before display.
-
#success ⇒ Array<String>
Successfull schema titles.
- #validate_all ⇒ Object
- #validate_data ⇒ Object
- #validate_schemas ⇒ Object
Instance Attribute Details
#files_to_validate ⇒ Array<String>
Returns file paths.
24 25 26 |
# File 'lib/json_schema_validator/base.rb', line 24 def files_to_validate @files_to_validate end |
Class Method Details
.run(files) ⇒ Object
Run the given validator with all schema files
27 28 29 30 31 32 |
# File 'lib/json_schema_validator/base.rb', line 27 def self.run(files) v = new(files) v.log << "Running validation with #{name} for #{files.length} schemas" v.validate_all v end |
Instance Method Details
#errors ⇒ Array<String>
Returns error schemas.
67 68 69 |
# File 'lib/json_schema_validator/base.rb', line 67 def errors @errors ||= [] end |
#log ⇒ Array<String>
Returns test log.
71 72 73 |
# File 'lib/json_schema_validator/base.rb', line 71 def log @log ||= [] end |
#log_fmt ⇒ Object
Joins the logs before display
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/json_schema_validator/base.rb', line 56 def log_fmt res = [] if errors.length > 0 res << "#{errors.join("\n\n")}" res << "="*50 res << "#{errors.length} with errors" end res << "#{success.uniq.length} Schemas passed" res.join("\n") end |
#success ⇒ Array<String>
Returns successfull schema titles.
75 76 77 |
# File 'lib/json_schema_validator/base.rb', line 75 def success @success ||= [] end |
#validate_all ⇒ Object
34 35 36 37 |
# File 'lib/json_schema_validator/base.rb', line 34 def validate_all validate_schemas validate_data end |
#validate_data ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/json_schema_validator/base.rb', line 47 def validate_data files_to_validate.each do |file| schema = File.read file log << "validate data against: #{file}" use_for_validation schema end end |
#validate_schemas ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/json_schema_validator/base.rb', line 39 def validate_schemas files_to_validate.each do |file| schema = File.read file log << "validate schema: #{file}" validate schema end end |