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"
- X_CONTENT_TYPE_OPTIONS =
"x-content-type-options"
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.
98 99 100 |
# File 'lib/sidekiq/web.rb', line 98 def app_url @app_url end |
.locales ⇒ Object
70 71 72 |
# File 'lib/sidekiq/web.rb', line 70 def locales @locales ||= LOCALES end |
.redis_pool ⇒ Object
Returns the value of attribute redis_pool.
98 99 100 |
# File 'lib/sidekiq/web.rb', line 98 def redis_pool @redis_pool end |
.views ⇒ Object
74 75 76 |
# File 'lib/sidekiq/web.rb', line 74 def views @views ||= VIEWS end |
Class Method Details
.call(env) ⇒ Object
124 125 126 127 |
# File 'lib/sidekiq/web.rb', line 124 def self.call(env) @app ||= new @app.call(env) end |
.custom_job_info_rows ⇒ Object
66 67 68 |
# File 'lib/sidekiq/web.rb', line 66 def custom_job_info_rows @custom_job_info_rows ||= [] end |
.custom_tabs ⇒ Object Also known as: tabs
61 62 63 |
# File 'lib/sidekiq/web.rb', line 61 def custom_tabs @custom_tabs ||= {} end |
.default_tabs ⇒ Object
57 58 59 |
# File 'lib/sidekiq/web.rb', line 57 def default_tabs DEFAULT_TABS end |
.disable(*opts) ⇒ Object
82 83 84 |
# File 'lib/sidekiq/web.rb', line 82 def disable(*opts) opts.each { |key| set(key, false) } end |
.enable(*opts) ⇒ Object
78 79 80 |
# File 'lib/sidekiq/web.rb', line 78 def enable(*opts) opts.each { |key| set(key, true) } end |
.inherited(child) ⇒ Object
102 103 104 105 |
# File 'lib/sidekiq/web.rb', line 102 def self.inherited(child) child.app_url = app_url child.redis_pool = redis_pool end |
.middlewares ⇒ Object
86 87 88 |
# File 'lib/sidekiq/web.rb', line 86 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.
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 189 190 |
# File 'lib/sidekiq/web.rb', line 160 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
94 95 96 |
# File 'lib/sidekiq/web.rb', line 94 def set(attribute, value) send(:"#{attribute}=", value) end |
.settings ⇒ Object
53 54 55 |
# File 'lib/sidekiq/web.rb', line 53 def settings self end |
.use(*args, &block) ⇒ Object
90 91 92 |
# File 'lib/sidekiq/web.rb', line 90 def use(*args, &block) middlewares << [args, block] end |
Instance Method Details
#app ⇒ Object
129 130 131 |
# File 'lib/sidekiq/web.rb', line 129 def app @app ||= build end |
#call(env) ⇒ Object
119 120 121 122 |
# File 'lib/sidekiq/web.rb', line 119 def call(env) env[:csp_nonce] = SecureRandom.base64(16) app.call(env) end |
#disable(*opts) ⇒ Object
137 138 139 |
# File 'lib/sidekiq/web.rb', line 137 def disable(*opts) opts.each { |key| set(key, false) } end |
#enable(*opts) ⇒ Object
133 134 135 |
# File 'lib/sidekiq/web.rb', line 133 def enable(*opts) opts.each { |key| set(key, true) } end |
#middlewares ⇒ Object
111 112 113 |
# File 'lib/sidekiq/web.rb', line 111 def middlewares @middlewares ||= self.class.middlewares end |
#set(attribute, value) ⇒ Object
141 142 143 |
# File 'lib/sidekiq/web.rb', line 141 def set(attribute, value) send(:"#{attribute}=", value) end |
#settings ⇒ Object
107 108 109 |
# File 'lib/sidekiq/web.rb', line 107 def settings self.class.settings end |
#use(*args, &block) ⇒ Object
115 116 117 |
# File 'lib/sidekiq/web.rb', line 115 def use(*args, &block) middlewares << [args, block] end |