Class: Commands::ValidateSchema
- Inherits:
-
Object
- Object
- Commands::ValidateSchema
- Defined in:
- lib/commands/validate_schema.rb
Instance Attribute Summary collapse
-
#detect ⇒ Object
Returns the value of attribute detect.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#extra_schemas ⇒ Object
Returns the value of attribute extra_schemas.
-
#messages ⇒ Object
Returns the value of attribute messages.
Instance Method Summary collapse
-
#initialize ⇒ ValidateSchema
constructor
A new instance of ValidateSchema.
- #run(argv) ⇒ Object
Constructor Details
#initialize ⇒ ValidateSchema
Returns a new instance of ValidateSchema.
11 12 13 14 15 16 17 |
# File 'lib/commands/validate_schema.rb', line 11 def initialize @detect = false @extra_schemas = [] @errors = [] = [] end |
Instance Attribute Details
#detect ⇒ Object
Returns the value of attribute detect.
5 6 7 |
# File 'lib/commands/validate_schema.rb', line 5 def detect @detect end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/commands/validate_schema.rb', line 8 def errors @errors end |
#extra_schemas ⇒ Object
Returns the value of attribute extra_schemas.
6 7 8 |
# File 'lib/commands/validate_schema.rb', line 6 def extra_schemas @extra_schemas end |
#messages ⇒ Object
Returns the value of attribute messages.
9 10 11 |
# File 'lib/commands/validate_schema.rb', line 9 def end |
Instance Method Details
#run(argv) ⇒ Object
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 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/commands/validate_schema.rb', line 19 def run(argv) return false if !initialize_store if !detect return false if !(schema_file = argv.shift) return false if !(schema = parse(schema_file)) end # if there are no remaining files in arguments, also a problem return false if argv.count < 1 argv.each do |data_file| return false if !check_file(data_file) data = JSON.parse(File.read(data_file)) if detect if !(schema_uri = data["$schema"]) @errors = ["#{data_file}: No $schema tag for detection."] return false end if !(schema = @store.lookup_uri(schema_uri)) @errors = ["#{data_file}: Unknown $schema, try specifying one with -s."] return false end end valid, errors = schema.validate(data) if valid += ["#{data_file} is valid."] else @errors = map_schema_errors(data_file, errors) end end @errors.empty? end |