Module: Sidekiq::Antidote::Web

Defined in:
lib/sidekiq/antidote/web.rb

Constant Summary collapse

VIEWS =
Pathname.new(__dir__).join("../../../web/views").expand_path

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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
# File 'lib/sidekiq/antidote/web.rb', line 11

def self.registered(app) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  app.get("/antidote") do
    @inhibitors = Antidote.inhibitors

    erb(VIEWS.join("index.html.erb").read)
  end

  app.get("/antidote/add") do
    @treatment       = Sidekiq::Antidote::Inhibitor::TREATMENTS.first
    @class_qualifier = ""

    erb(VIEWS.join("add.html.erb").read)
  end

  app.post("/antidote/add") do
    @treatment             = params[:treatment]
    @treatment             = "skip" unless Sidekiq::Antidote::Inhibitor::TREATMENTS.include?(@treatment)
    @class_qualifier       = params[:class_qualifier]
    @class_qualifier_error = nil

    begin
      Sidekiq::Antidote::ClassQualifier.new(@class_qualifier)
    rescue StandardError => e
      @class_qualifier_error = e.message
    end

    if @class_qualifier_error
      erb(VIEWS.join("add.html.erb").read)
    else
      Antidote.add(treatment: @treatment, class_qualifier: @class_qualifier)
      redirect "#{root_path}antidote"
    end
  end

  app.post("/antidote/:id/delete") do
    Antidote.delete(route_params[:id])

    redirect "#{root_path}antidote"
  end
end