forked from akiellor/coder
-
Notifications
You must be signed in to change notification settings - Fork 9
/
repository.rb
43 lines (33 loc) · 812 Bytes
/
repository.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'grape'
require 'sequel'
class Repository < Grape::API
version 'v1'
default_format :json
helpers do
def forks
Sequel::DATABASES.first[:forks]
end
def default_fork
path = env['repository.path']
scripts = Dir[File.join(path, '*.js')].map do |src_path|
spec_name = File.basename(src_path).gsub /\.js$/, ''
spec_path = File.join path, 'spec', spec_name + '_spec.js'
src = File.open(src_path).read
spec = File.open(spec_path).read
[spec_name, {src: src, spec: spec}]
end
Hash[scripts]
end
end
resource :forks do
get 'new' do
default_fork
end
post 'new' do
{id: forks.insert(data: request.body.read)}
end
get ':id' do
forks[id: params[:id]][:data]
end
end
end