class Sidekiq::WebApplication
Constants
- CONTENT_LENGTH
- CONTENT_TYPE
- CSP_HEADER
- REDIS_KEYS
Public Class Methods
after(path=nil, &block)
click to toggle source
# File lib/sidekiq/web/application.rb, line 331 def self.after(path=nil, &block) afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block] end
afters()
click to toggle source
# File lib/sidekiq/web/application.rb, line 352 def self.afters @afters ||= [] end
before(path=nil, &block)
click to toggle source
# File lib/sidekiq/web/application.rb, line 327 def self.before(path=nil, &block) befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block] end
befores()
click to toggle source
# File lib/sidekiq/web/application.rb, line 348 def self.befores @befores ||= [] end
helpers(mod=nil, &block)
click to toggle source
# File lib/sidekiq/web/application.rb, line 319 def self.helpers(mod=nil, &block) if block_given? WebAction.class_eval(&block) else WebAction.send(:include, mod) end end
new(klass)
click to toggle source
# File lib/sidekiq/web/application.rb, line 26 def initialize(klass) @klass = klass end
run_afters(app, action)
click to toggle source
# File lib/sidekiq/web/application.rb, line 339 def self.run_afters(app, action) run_hooks(afters, app, action) end
run_befores(app, action)
click to toggle source
# File lib/sidekiq/web/application.rb, line 335 def self.run_befores(app, action) run_hooks(befores, app, action) end
run_hooks(hooks, app, action)
click to toggle source
# File lib/sidekiq/web/application.rb, line 343 def self.run_hooks(hooks, app, action) hooks.select { |p,_| !p || p =~ action.env[WebRouter::PATH_INFO] }. each {|_,b| action.instance_exec(action.env, app, &b) } end
set(key, val)
click to toggle source
# File lib/sidekiq/web/application.rb, line 42 def self.set(key, val) # nothing, backwards compatibility end
settings()
click to toggle source
# File lib/sidekiq/web/application.rb, line 34 def self.settings Sidekiq::Web.settings end
tabs()
click to toggle source
# File lib/sidekiq/web/application.rb, line 38 def self.tabs Sidekiq::Web.tabs end
Public Instance Methods
call(env)
click to toggle source
# File lib/sidekiq/web/application.rb, line 282 def call(env) action = self.class.match(env) return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass" }, ["Not Found"]] unless action resp = catch(:halt) do app = @klass self.class.run_befores(app, action) begin resp = action.instance_exec env, &action.block ensure self.class.run_afters(app, action) end resp end resp = case resp when Array resp else headers = { "Content-Type" => "text/html", "Cache-Control" => "no-cache", "Content-Language" => action.locale, "Content-Security-Policy" => CSP_HEADER } [200, headers, [resp]] end resp[1] = resp[1].dup resp[1][CONTENT_LENGTH] = resp[2].inject(0) { |l, p| l + p.bytesize }.to_s resp end
settings()
click to toggle source
# File lib/sidekiq/web/application.rb, line 30 def settings @klass.settings end