Module: TableSchema::Validate

Included in:
Schema
Defined in:
lib/tableschema/validate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/tableschema/validate.rb', line 4

def errors
  @errors
end

Instance Method Details

#load_validator!Object



6
7
8
9
# File 'lib/tableschema/validate.rb', line 6

def load_validator!
  filepath = File.join(File.dirname(__FILE__), '..', 'profiles', 'table-schema.json')
  @profile ||= JSON.parse(File.read(filepath), symbolize_names: true)
end

#validateObject



11
12
13
14
15
16
# File 'lib/tableschema/validate.rb', line 11

def validate
  @errors = Set.new(JSON::Validator.fully_validate(@profile, self))
  check_primary_keys
  check_foreign_keys
  @errors.empty?
end

#validate!Object

Raises:



18
19
20
21
22
# File 'lib/tableschema/validate.rb', line 18

def validate!
  validate
  raise SchemaException.new(@errors.first) unless @errors.empty?
  true
end