class RestKat::Validator
validator class for answers
Public Class Methods
find_resource(resource, schema)
click to toggle source
# File lib/rest_kat/validator.rb, line 19 def self.find_resource resource, schema schema["resources"].find do |r| r["name"].to_s == resource.to_s end end
for_resource(resource, file)
click to toggle source
# File lib/rest_kat/validator.rb, line 25 def self.for_resource resource, file schema = load_schema file type = find_resource(resource, schema)["type"] raise Exception.new("Can't find resource '#{resource}'") unless type Validator.new type end
for_resource_collection(resource, file)
click to toggle source
# File lib/rest_kat/validator.rb, line 39 def self.for_resource_collection resource, file schema = load_schema file type = find_resource(resource, schema)["type"] collection_type = { "type" => "seq", "sequence" => [ type ] } Validator.new collection_type end
for_type(type, file)
click to toggle source
# File lib/rest_kat/validator.rb, line 32 def self.for_type type, file schema = load_schema file type = schema[type.to_s] raise Exception.new("Can't find resource '#{resource}'") unless type Validator.new type end
load_schema(file)
click to toggle source
# File lib/rest_kat/validator.rb, line 11 def self.load_schema file Kwalify::Yaml.load_file file end
new(type)
click to toggle source
Calls superclass method
# File lib/rest_kat/validator.rb, line 15 def initialize type super (@resource_schema=type) end
Public Instance Methods
schema()
click to toggle source
# File lib/rest_kat/validator.rb, line 7 def schema @schema end