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.
-
#fail_fast ⇒ Object
Returns the value of attribute fail_fast.
-
#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.
14 15 16 17 18 19 20 21 |
# File 'lib/commands/validate_schema.rb', line 14 def initialize @detect = false @fail_fast = 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.
11 12 13 |
# File 'lib/commands/validate_schema.rb', line 11 def errors @errors end |
#extra_schemas ⇒ Object
Returns the value of attribute extra_schemas.
9 10 11 |
# File 'lib/commands/validate_schema.rb', line 9 def extra_schemas @extra_schemas end |
#fail_fast ⇒ Object
Returns the value of attribute fail_fast.
8 9 10 |
# File 'lib/commands/validate_schema.rb', line 8 def fail_fast @fail_fast end |
#messages ⇒ Object
Returns the value of attribute messages.
12 13 14 |
# File 'lib/commands/validate_schema.rb', line 12 def @messages end |
Instance Method Details
#run(argv) ⇒ Object
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 60 61 |
# File 'lib/commands/validate_schema.rb', line 23 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, fail_fast: fail_fast) if valid @messages += ["#{data_file} is valid."] else @errors = map_schema_errors(data_file, errors) end end @errors.empty? end |