Class: Cosmo::Web

Inherits:
Object
  • Object
show all
Includes:
Renderer
Defined in:
lib/cosmo/web.rb,
lib/cosmo/web/context.rb,
lib/cosmo/web/renderer.rb,
lib/cosmo/web/controllers/jobs.rb,
lib/cosmo/web/controllers/crons.rb,
lib/cosmo/web/controllers/actions.rb,
lib/cosmo/web/controllers/batches.rb,
lib/cosmo/web/controllers/streams.rb,
lib/cosmo/web/helpers/application.rb,
lib/cosmo/web/controllers/application.rb

Defined Under Namespace

Modules: Controllers, Helpers, Renderer Classes: Context

Constant Summary

Constants included from Renderer

Renderer::ASSETS_ROOT, Renderer::VIEWS_ROOT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Renderer

#no_content, #not_found, #ok, #redirect_to, #serve, #url_for

Class Method Details

.call(env) ⇒ Object



19
20
21
# File 'lib/cosmo/web.rb', line 19

def self.call(env)
  new.call(env)
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



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
# File 'lib/cosmo/web.rb', line 23

def call(env) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
  @request = Rack::Request.new(env)
  path     = @request.path_info
  method   = @request.request_method

  response = case [method.downcase.to_sym, path]
             in [:get,    "/"]                      then redirect_to("/jobs")
             in [:get,    "/jobs"]                  then [Controllers::Jobs,    :index]
             in [:get,    "/jobs/scheduled"]        then [Controllers::Jobs,    :scheduled]
             in [:get,    "/jobs/dead"]             then [Controllers::Jobs,    :dead]
             in [:get,    "/jobs/busy"]             then [Controllers::Jobs,    :busy]
             in [:get,    "/jobs/enqueued"]         then [Controllers::Jobs,    :enqueued]
             in [:patch,  %r{/jobs/retry/\d+}]      then [Controllers::Jobs,    :retry]
             in [:delete, %r{/jobs/delete/\d+}]     then [Controllers::Jobs,    :delete]
             in [:get,    "/jobs/_stats"]           then [Controllers::Jobs,    :_stats]
             in [:get,    "/jobs/_scheduled"]       then [Controllers::Jobs,    :_scheduled]
             in [:get,    "/jobs/_dead"]            then [Controllers::Jobs,    :_dead]
             in [:get,    "/jobs/_busy"]            then [Controllers::Jobs,    :_busy]
             in [:get,    "/jobs/_enqueued"]        then [Controllers::Jobs,    :_enqueued]
             in [:get,    "/streams"]               then [Controllers::Streams, :index]
             in [:get,    "/streams/info"]          then [Controllers::Streams, :info]
             in [:get,    "/streams/_table"]        then [Controllers::Streams, :_table]
             in [:get,    "/streams/_info"]         then [Controllers::Streams, :_info]
             in [:patch,  "/streams/pause"]         then [Controllers::Streams, :pause]
             in [:patch,  "/streams/unpause"]       then [Controllers::Streams, :unpause]
             in [:get,    "/crons"]                 then [Controllers::Crons,   :index]
             in [:get,    "/crons/_table"]          then [Controllers::Crons,   :_table]
             in [:delete, "/crons/delete"]          then [Controllers::Crons,   :delete]
             in [:post,   "/crons/run"]             then [Controllers::Crons,   :run_now]
             in [:get,    "/batches"]               then [Controllers::Batches, :index]
             in [:get,    "/batches/_table"]        then [Controllers::Batches, :_table]
             in [:get,    "/actions"]               then [Controllers::Actions, :index]
             in [:get,    "/assets/htmx.min.js.gz"] then serve("htmx.2.0.8.min.js.gz",
                                                               "application/javascript",
                                                               { "content-encoding" => "gzip" })
             in [:get, "/assets/app.css"]         then serve("app.css", "text/css")
             in [:get, "/favicon.ico"]            then no_content
             else not_found
             end
  handler(response)
end