Module: StoplightAdmin::Application

Defined in:
lib/stoplight_admin/application.rb,
lib/stoplight_admin/application/helpers.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



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
# File 'lib/stoplight_admin/application.rb', line 10

def self.registered(app)
  app.helpers Application::Helpers

  app.set :data_store, nil
  app.set :views, File.join(File.dirname(__FILE__), "views")

  app.get "/" do
    lights, stats = dependencies.home_action.call

    erb :index, locals: stats.merge(lights: lights)
  end

  app.get "/stats" do
    lights, stats = dependencies.stats_action.call

    json({stats: stats, lights: lights.map(&:as_json)})
  end

  app.post "/lock" do
    dependencies.lock_action.call(params)

    redirect to("/")
  end

  app.post "/unlock" do
    dependencies.unlock_action.call(params)

    redirect to("/")
  end

  app.post "/green" do
    dependencies.green_action.call(params)

    redirect to("/")
  end

  app.post "/red" do
    dependencies.red_action.call(params)

    redirect to("/")
  end

  app.post "/green_all" do
    dependencies.green_all_action.call

    redirect to("/")
  end
end