-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.rb
89 lines (68 loc) · 1.75 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require "roda"
require "uploaders/image"
class ShrineRomDemo < Roda
use Rack::MethodOverride
plugin :all_verbs
plugin :indifferent_params
include Import[album_repo: "persistence.repositories.album"]
route do |r|
r.root do
r.redirect "/albums"
end
r.on "albums" do
r.get true do
view "albums.index"
end
r.get "new" do
view "albums.new"
end
r.post true do
operation "albums.create", params[:album] do |m|
m.success do |album|
r.redirect "/albums/#{album.id}/edit"
end
m.failure do |validation|
view "albums.new", validation: validation
end
end
end
r.is Integer do |album_id|
album = album_repo.find_with_photos(album_id) or not_found!
r.get "edit" do
view "albums.edit", album: album
end
r.put do
operation "albums.update", album, params[:album] do |m|
m.success do |album|
r.redirect "/albums/#{album.id}/edit"
end
m.failure do |validation|
view "albums.edit", album: album, validation: validation
end
end
end
r.delete do
operation "albums.delete", album
r.redirect "/albums"
end
end
end
r.on "upload" do
r.run Uploaders::Base.upload_endpoint(:cache)
end
r.on "derivations/image" do
r.run Uploaders::Image.derivation_endpoint
end
end
private
def view(name, *args)
Container["views.#{name}"].call(*args)
end
def operation(name, *args, &block)
Container["operations.#{name}"].call(*args, &block)
end
def not_found!
response.status = 404
request.halt
end
end