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.
13 14 15 16 17 18 19 |
# File 'lib/commands/validate_schema.rb', line 13 def initialize @detect = false @extra_schemas = [] @errors = [] @messages = [] end |
Instance Attribute Details
#detect ⇒ Object
Returns the value of attribute detect.
7 8 9 |
# File 'lib/commands/validate_schema.rb', line 7 def detect @detect end |
#errors ⇒ Object
Returns the value of attribute errors.
10 11 12 |
# File 'lib/commands/validate_schema.rb', line 10 def errors @errors end |
#extra_schemas ⇒ Object
Returns the value of attribute extra_schemas.
8 9 10 |
# File 'lib/commands/validate_schema.rb', line 8 def extra_schemas @extra_schemas end |
#messages ⇒ Object
Returns the value of attribute messages.
11 12 13 |
# File 'lib/commands/validate_schema.rb', line 11 def @messages end |
Instance Method Details
#run(argv) ⇒ Object
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 57 58 59 |
# File 'lib/commands/validate_schema.rb', line 21 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| if !(data = read_file(data_file)) return false end if detect if !(schema_uri = data["$schema"]) @errors = ["#{data_file}: No $schema tag for detection."] return false end if !(schema = @store.lookup_schema(schema_uri)) @errors = ["#{data_file}: Unknown $schema, try specifying one with -s."] return false end end valid, errors = schema.validate(data) if valid @messages += ["#{data_file} is valid."] else @errors = map_schema_errors(data_file, errors) end end @errors.empty? end |