3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/brief/server/handlers/schema.rb', line 3
def self.handle(path_args, briefcase, options)
request = options.fetch(:request)
= {"Content-Type"=>"application/json"}
if request.path == "/schema"
[200, , Brief::Model.classes.map(&:to_schema)]
elsif request.path.match(/^\/schema\/(.+)$/)
requested = request.path.split("/").last
if model = Brief::Model.lookup(requested)
[200, , model.to_schema]
else
[404, , {error: "Can not find model class matching #{ requested }"}]
end
end
end
|