You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/lib/carto/legend_definition_validator.rb

32 lines
790 B

require 'json-schema'
require_dependency 'carto/definition'
module Carto
class LegendDefinitionValidator
def initialize(type, definition)
@type = type
@definition = definition.with_indifferent_access if definition
end
def errors
return @errors if @errors
return ['could not be validated'] unless @definition && location
schema = Carto::Definition.instance.load_from_file(location)
@errors = JSON::Validator.fully_validate(schema, @definition)
end
private
LEGEND_FORMATS_LOCATION = 'lib/formats/legends/definitions'.freeze
def location
return @location if @location
location = "#{Rails.root}/#{LEGEND_FORMATS_LOCATION}/#{@type}.json"
@location = location if File.exists?(location)
end
end
end