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
-
.configure {|_self| ... } ⇒ Object
Forward compatibility with 8.0.
- .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.
103 104 105 |
# File 'lib/sidekiq/web.rb', line 103 def app_url @app_url end |
.locales ⇒ Object
75 76 77 |
# File 'lib/sidekiq/web.rb', line 75 def locales @locales ||= LOCALES end |
.redis_pool ⇒ Object
Returns the value of attribute redis_pool.
103 104 105 |
# File 'lib/sidekiq/web.rb', line 103 def redis_pool @redis_pool end |
.views ⇒ Object
79 80 81 |
# File 'lib/sidekiq/web.rb', line 79 def views @views ||= VIEWS end |
Class Method Details
.call(env) ⇒ Object
129 130 131 132 |
# File 'lib/sidekiq/web.rb', line 129 def self.call(env) @app ||= new @app.call(env) end |
.configure {|_self| ... } ⇒ Object
Forward compatibility with 8.0
54 55 56 |
# File 'lib/sidekiq/web.rb', line 54 def configure yield self end |
.custom_job_info_rows ⇒ Object
71 72 73 |
# File 'lib/sidekiq/web.rb', line 71 def custom_job_info_rows @custom_job_info_rows ||= [] end |
.custom_tabs ⇒ Object Also known as: tabs
66 67 68 |
# File 'lib/sidekiq/web.rb', line 66 def custom_tabs @custom_tabs ||= {} end |
.default_tabs ⇒ Object
62 63 64 |
# File 'lib/sidekiq/web.rb', line 62 def default_tabs DEFAULT_TABS end |
.disable(*opts) ⇒ Object
87 88 89 |
# File 'lib/sidekiq/web.rb', line 87 def disable(*opts) opts.each { |key| set(key, false) } end |
.enable(*opts) ⇒ Object
83 84 85 |
# File 'lib/sidekiq/web.rb', line 83 def enable(*opts) opts.each { |key| set(key, true) } end |
.inherited(child) ⇒ Object
107 108 109 110 |
# File 'lib/sidekiq/web.rb', line 107 def self.inherited(child) child.app_url = app_url child.redis_pool = redis_pool end |
.middlewares ⇒ Object
91 92 93 |
# File 'lib/sidekiq/web.rb', line 91 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.
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 191 192 193 194 195 |
# File 'lib/sidekiq/web.rb', line 165 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
99 100 101 |
# File 'lib/sidekiq/web.rb', line 99 def set(attribute, value) send(:"#{attribute}=", value) end |
.settings ⇒ Object
58 59 60 |
# File 'lib/sidekiq/web.rb', line 58 def settings self end |
.use(*args, &block) ⇒ Object
95 96 97 |
# File 'lib/sidekiq/web.rb', line 95 def use(*args, &block) middlewares << [args, block] end |
Instance Method Details
#app ⇒ Object
134 135 136 |
# File 'lib/sidekiq/web.rb', line 134 def app @app ||= build end |
#call(env) ⇒ Object
124 125 126 127 |
# File 'lib/sidekiq/web.rb', line 124 def call(env) env[:csp_nonce] = SecureRandom.base64(16) app.call(env) end |
#disable(*opts) ⇒ Object
142 143 144 |
# File 'lib/sidekiq/web.rb', line 142 def disable(*opts) opts.each { |key| set(key, false) } end |
#enable(*opts) ⇒ Object
138 139 140 |
# File 'lib/sidekiq/web.rb', line 138 def enable(*opts) opts.each { |key| set(key, true) } end |
#middlewares ⇒ Object
116 117 118 |
# File 'lib/sidekiq/web.rb', line 116 def middlewares @middlewares ||= self.class.middlewares end |
#set(attribute, value) ⇒ Object
146 147 148 |
# File 'lib/sidekiq/web.rb', line 146 def set(attribute, value) send(:"#{attribute}=", value) end |
#settings ⇒ Object
112 113 114 |
# File 'lib/sidekiq/web.rb', line 112 def settings self.class.settings end |
#use(*args, &block) ⇒ Object
120 121 122 |
# File 'lib/sidekiq/web.rb', line 120 def use(*args, &block) middlewares << [args, block] end |