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
|
# File 'lib/coupler/extensions/matchers.rb', line 4
def self.registered(app)
app.get "/projects/:project_id/scenarios/:scenario_id/matchers/new" do
@scenario = @project.scenarios_dataset[:id => params[:scenario_id]]
raise ScenarioNotFound unless @scenario
@resources = @scenario.resources
@matcher = Models::Matcher.new
erb 'matchers/form'.to_sym
end
app.get "/projects/:project_id/scenarios/:scenario_id/matchers/:id/edit" do
@scenario = @project.scenarios_dataset[:id => params[:scenario_id]]
raise ScenarioNotFound unless @scenario
@matcher = @scenario.matcher_dataset[:id => params[:id]]
raise MatcherNotFound unless @matcher
@resources = @scenario.resources
erb 'matchers/form'.to_sym
end
app.post "/projects/:project_id/scenarios/:scenario_id/matchers" do
@scenario = @project.scenarios_dataset[:id => params[:scenario_id]]
raise ScenarioNotFound unless @scenario
@matcher = Models::Matcher.new(params[:matcher])
@matcher.scenario = @scenario
if @matcher.save
flash[:notice] = "Matcher was successfully created."
redirect "/projects/#{@project.id}/scenarios/#{@scenario.id}"
else
@resources = @scenario.resources
erb 'matchers/form'.to_sym
end
end
app.put "/projects/:project_id/scenarios/:scenario_id/matchers/:id" do
@scenario = @project.scenarios_dataset[:id => params[:scenario_id]]
raise ScenarioNotFound unless @scenario
@matcher = @scenario.matcher_dataset[:id => params[:id]]
raise MatcherNotFound unless @matcher
@matcher.set(params[:matcher])
if @matcher.valid?
@matcher.save
redirect "/projects/#{@project.id}/scenarios/#{@scenario.id}"
else
@resources = @scenario.resources
erb 'matchers/form'.to_sym
end
end
app.delete "/projects/:project_id/scenarios/:scenario_id/matchers/:id" do
@scenario = @project.scenarios_dataset[:id => params[:scenario_id]]
raise ScenarioNotFound unless @scenario
@matcher = @scenario.matcher_dataset[:id => params[:id]]
raise MatcherNotFound unless @matcher
@matcher.destroy
redirect "/projects/#{@project.id}/scenarios/#{@scenario.id}"
end
end
|