Class: Sidekiq::Web
- Inherits:
-
Object
- Object
- Sidekiq::Web
- Defined in:
- lib/sidekiq/web.rb,
lib/sidekiq/web/csrf_protection.rb
Defined Under Namespace
Classes: CsrfProtection
Constant Summary collapse
- ROOT =
File.("#{File.dirname(__FILE__)}/../../web")
- VIEWS =
"#{ROOT}/views"
- LOCALES =
["#{ROOT}/locales"]
- LAYOUT =
"#{VIEWS}/layout.erb"
- ASSETS =
"#{ROOT}/assets"
- DEFAULT_TABS =
{ "Dashboard" => "", "Busy" => "busy", "Queues" => "queues", "Retries" => "retries", "Scheduled" => "scheduled", "Dead" => "morgue", "Metrics" => "metrics" }
- CONTENT_LANGUAGE =
"content-language"
- CONTENT_SECURITY_POLICY =
"content-security-policy"
- LOCATION =
"location"
- X_CASCADE =
"x-cascade"
Class Attribute Summary collapse
-
.app_url ⇒ Object
Returns the value of attribute app_url.
- .locales ⇒ Object
-
.redis_pool ⇒ Object
Returns the value of attribute redis_pool.
- .views ⇒ Object
Class Method Summary collapse
- .call(env) ⇒ Object
- .custom_job_info_rows ⇒ Object
- .custom_tabs ⇒ Object (also: tabs)
- .default_tabs ⇒ Object
- .disable(*opts) ⇒ Object
- .enable(*opts) ⇒ Object
- .inherited(child) ⇒ Object
- .middlewares ⇒ Object
-
.register(extension, name: nil, tab: nil, index: nil, root_dir: nil, cache_for: 86400, asset_paths: nil) {|_self| ... } ⇒ Object
Register a class as a Sidekiq Web UI extension.
- .set(attribute, value) ⇒ Object
- .settings ⇒ Object
- .use(*args, &block) ⇒ Object
Instance Method Summary collapse
- #app ⇒ Object
- #call(env) ⇒ Object
- #disable(*opts) ⇒ Object
- #enable(*opts) ⇒ Object
- #middlewares ⇒ Object
- #set(attribute, value) ⇒ Object
- #settings ⇒ Object
- #use(*args, &block) ⇒ Object
Class Attribute Details
.app_url ⇒ Object
Returns the value of attribute app_url.
96 97 98 |
# File 'lib/sidekiq/web.rb', line 96 def app_url @app_url end |
.locales ⇒ Object
68 69 70 |
# File 'lib/sidekiq/web.rb', line 68 def locales @locales ||= LOCALES end |
.redis_pool ⇒ Object
Returns the value of attribute redis_pool.
96 97 98 |
# File 'lib/sidekiq/web.rb', line 96 def redis_pool @redis_pool end |
.views ⇒ Object
72 73 74 |
# File 'lib/sidekiq/web.rb', line 72 def views @views ||= VIEWS end |
Class Method Details
.call(env) ⇒ Object
122 123 124 125 |
# File 'lib/sidekiq/web.rb', line 122 def self.call(env) @app ||= new @app.call(env) end |
.custom_job_info_rows ⇒ Object
64 65 66 |
# File 'lib/sidekiq/web.rb', line 64 def custom_job_info_rows @custom_job_info_rows ||= [] end |
.custom_tabs ⇒ Object Also known as: tabs
59 60 61 |
# File 'lib/sidekiq/web.rb', line 59 def custom_tabs @custom_tabs ||= {} end |
.default_tabs ⇒ Object
55 56 57 |
# File 'lib/sidekiq/web.rb', line 55 def default_tabs DEFAULT_TABS end |
.disable(*opts) ⇒ Object
80 81 82 |
# File 'lib/sidekiq/web.rb', line 80 def disable(*opts) opts.each { |key| set(key, false) } end |
.enable(*opts) ⇒ Object
76 77 78 |
# File 'lib/sidekiq/web.rb', line 76 def enable(*opts) opts.each { |key| set(key, true) } end |
.inherited(child) ⇒ Object
100 101 102 103 |
# File 'lib/sidekiq/web.rb', line 100 def self.inherited(child) child.app_url = app_url child.redis_pool = redis_pool end |
.middlewares ⇒ Object
84 85 86 |
# File 'lib/sidekiq/web.rb', line 84 def middlewares @middlewares ||= [] end |
.register(extension, name: nil, tab: nil, index: nil, root_dir: nil, cache_for: 86400, asset_paths: nil) {|_self| ... } ⇒ Object
Register a class as a Sidekiq Web UI extension. The class should provide one or more tabs which map to an index route. Options:
TODO name, tab and index will be mandatory in 8.0
Web extensions will have a root ‘web/` directory with `locales/`, `assets/` and `views/` subdirectories.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/sidekiq/web.rb', line 158 def self.register(extension, name: nil, tab: nil, index: nil, root_dir: nil, cache_for: 86400, asset_paths: nil) tab = Array(tab) index = Array(index) tab.zip(index).each do |tab, index| tabs[tab] = index end if root_dir locdir = File.join(root_dir, "locales") locales << locdir if File.directory?(locdir) if asset_paths && name # if you have {root}/assets/{name}/js/scripts.js # and {root}/assets/{name}/css/styles.css # you would pass in: # asset_paths: ["js", "css"] # See script_tag and style_tag in web/helpers.rb assdir = File.join(root_dir, "assets") assurls = Array(asset_paths).map { |x| "/#{name}/#{x}" } assetprops = { urls: assurls, root: assdir, cascade: true } assetprops[:header_rules] = [[:all, {Rack::CACHE_CONTROL => "private, max-age=#{cache_for.to_i}"}]] if cache_for middlewares << [[Rack::Static, assetprops], nil] end end yield self if block_given? extension.registered(WebApplication) end |
.set(attribute, value) ⇒ Object
92 93 94 |
# File 'lib/sidekiq/web.rb', line 92 def set(attribute, value) send(:"#{attribute}=", value) end |
.settings ⇒ Object
51 52 53 |
# File 'lib/sidekiq/web.rb', line 51 def settings self end |
.use(*args, &block) ⇒ Object
88 89 90 |
# File 'lib/sidekiq/web.rb', line 88 def use(*args, &block) middlewares << [args, block] end |
Instance Method Details
#app ⇒ Object
127 128 129 |
# File 'lib/sidekiq/web.rb', line 127 def app @app ||= build end |
#call(env) ⇒ Object
117 118 119 120 |
# File 'lib/sidekiq/web.rb', line 117 def call(env) env[:csp_nonce] = SecureRandom.base64(16) app.call(env) end |
#disable(*opts) ⇒ Object
135 136 137 |
# File 'lib/sidekiq/web.rb', line 135 def disable(*opts) opts.each { |key| set(key, false) } end |
#enable(*opts) ⇒ Object
131 132 133 |
# File 'lib/sidekiq/web.rb', line 131 def enable(*opts) opts.each { |key| set(key, true) } end |
#middlewares ⇒ Object
109 110 111 |
# File 'lib/sidekiq/web.rb', line 109 def middlewares @middlewares ||= self.class.middlewares end |
#set(attribute, value) ⇒ Object
139 140 141 |
# File 'lib/sidekiq/web.rb', line 139 def set(attribute, value) send(:"#{attribute}=", value) end |
#settings ⇒ Object
105 106 107 |
# File 'lib/sidekiq/web.rb', line 105 def settings self.class.settings end |
#use(*args, &block) ⇒ Object
113 114 115 |
# File 'lib/sidekiq/web.rb', line 113 def use(*args, &block) middlewares << [args, block] end |