Class: Sidekiq::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/web.rb,
lib/sidekiq/web/csrf_protection.rb

Defined Under Namespace

Classes: CsrfProtection

Constant Summary collapse

ROOT =
File.expand_path("#{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"
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.app_urlObject

Returns the value of attribute app_url


81
82
83
# File 'lib/sidekiq/web.rb', line 81

def app_url
  @app_url
end

.localesObject


60
61
62
# File 'lib/sidekiq/web.rb', line 60

def locales
  @locales ||= LOCALES
end

.redis_poolObject

Returns the value of attribute redis_pool


81
82
83
# File 'lib/sidekiq/web.rb', line 81

def redis_pool
  @redis_pool
end

.session_secretObject

Returns the value of attribute session_secret


81
82
83
# File 'lib/sidekiq/web.rb', line 81

def session_secret
  @session_secret
end

.sessionsObject

Returns the value of attribute sessions


81
82
83
# File 'lib/sidekiq/web.rb', line 81

def sessions
  @sessions
end

.viewsObject


64
65
66
# File 'lib/sidekiq/web.rb', line 64

def views
  @views ||= VIEWS
end

Instance Attribute Details

#sessionsObject


134
135
136
137
138
139
140
141
# File 'lib/sidekiq/web.rb', line 134

def sessions
  unless instance_variable_defined?("@sessions")
    @sessions = self.class.sessions
    @sessions = @sessions.to_hash.dup if @sessions.respond_to?(:to_hash)
  end

  @sessions
end

Class Method Details

.call(env) ⇒ Object


108
109
110
111
# File 'lib/sidekiq/web.rb', line 108

def self.call(env)
  @app ||= new
  @app.call(env)
end

.custom_tabsObject Also known as: tabs


55
56
57
# File 'lib/sidekiq/web.rb', line 55

def custom_tabs
  @custom_tabs ||= {}
end

.default_tabsObject


51
52
53
# File 'lib/sidekiq/web.rb', line 51

def default_tabs
  DEFAULT_TABS
end

.disable(*opts) ⇒ Object


72
73
74
# File 'lib/sidekiq/web.rb', line 72

def disable(*opts)
  opts.each { |key| set(key, false) }
end

.enable(*opts) ⇒ Object


68
69
70
# File 'lib/sidekiq/web.rb', line 68

def enable(*opts)
  opts.each { |key| set(key, true) }
end

.inherited(child) ⇒ Object


85
86
87
88
89
90
# File 'lib/sidekiq/web.rb', line 85

def self.inherited(child)
  child.app_url = app_url
  child.session_secret = session_secret
  child.redis_pool = redis_pool
  child.sessions = sessions
end

.middlewaresObject


43
44
45
# File 'lib/sidekiq/web.rb', line 43

def middlewares
  @middlewares ||= []
end

.register(extension) ⇒ Object


143
144
145
# File 'lib/sidekiq/web.rb', line 143

def self.register(extension)
  extension.registered(WebApplication)
end

.set(attribute, value) ⇒ Object

Helper for the Sinatra syntax: Sidekiq::Web.set(:session_secret, Rails.application.secrets…)


77
78
79
# File 'lib/sidekiq/web.rb', line 77

def set(attribute, value)
  send(:"#{attribute}=", value)
end

.settingsObject


39
40
41
# File 'lib/sidekiq/web.rb', line 39

def settings
  self
end

.use(*middleware_args, &block) ⇒ Object


47
48
49
# File 'lib/sidekiq/web.rb', line 47

def use(*middleware_args, &block)
  middlewares << [middleware_args, block]
end

Instance Method Details

#appObject


113
114
115
# File 'lib/sidekiq/web.rb', line 113

def app
  @app ||= build
end

#call(env) ⇒ Object


104
105
106
# File 'lib/sidekiq/web.rb', line 104

def call(env)
  app.call(env)
end

#disable(*opts) ⇒ Object


121
122
123
# File 'lib/sidekiq/web.rb', line 121

def disable(*opts)
  opts.each { |key| set(key, false) }
end

#enable(*opts) ⇒ Object


117
118
119
# File 'lib/sidekiq/web.rb', line 117

def enable(*opts)
  opts.each { |key| set(key, true) }
end

#middlewaresObject


100
101
102
# File 'lib/sidekiq/web.rb', line 100

def middlewares
  @middlewares ||= Web.middlewares.dup
end

#set(attribute, value) ⇒ Object


125
126
127
# File 'lib/sidekiq/web.rb', line 125

def set(attribute, value)
  send(:"#{attribute}=", value)
end

#settingsObject


92
93
94
# File 'lib/sidekiq/web.rb', line 92

def settings
  self.class.settings
end

#use(*middleware_args, &block) ⇒ Object


96
97
98
# File 'lib/sidekiq/web.rb', line 96

def use(*middleware_args, &block)
  middlewares << [middleware_args, block]
end