Class: Slimer::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/slimer/web.rb,
lib/slimer/web/csfr_protection.rb

Overview

The Slimer web application on Rack Borrowed from Slidekiq: github.com/mperham/sidekiq/blob/master/lib/sidekiq/web.rb

Defined Under Namespace

Classes: CsrfProtection

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.



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

def app_url
  @app_url
end

.session_secretObject

Returns the value of attribute session_secret.



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

def session_secret
  @session_secret
end

.sessionsObject

Returns the value of attribute sessions.



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

def sessions
  @sessions
end

Instance Attribute Details

#sessionsObject



97
98
99
100
101
102
103
104
# File 'lib/slimer/web.rb', line 97

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



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

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

.disable(*opts) ⇒ Object



34
35
36
# File 'lib/slimer/web.rb', line 34

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

.enable(*opts) ⇒ Object



30
31
32
# File 'lib/slimer/web.rb', line 30

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

.inherited(child) ⇒ Object

rubocop:disable Lint/MissingSuper



47
48
49
50
51
52
# File 'lib/slimer/web.rb', line 47

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

.middlewaresObject



26
27
28
# File 'lib/slimer/web.rb', line 26

def middlewares
  @middlewares ||= []
end

.register(extension) ⇒ Object



106
107
108
# File 'lib/slimer/web.rb', line 106

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

.set(attribute, value) ⇒ Object

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



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

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

.settingsObject



22
23
24
# File 'lib/slimer/web.rb', line 22

def settings
  self
end

Instance Method Details

#appObject



76
77
78
# File 'lib/slimer/web.rb', line 76

def app
  @app ||= build
end

#call(env) ⇒ Object



67
68
69
# File 'lib/slimer/web.rb', line 67

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

#disable(*opts) ⇒ Object



84
85
86
# File 'lib/slimer/web.rb', line 84

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

#enable(*opts) ⇒ Object



80
81
82
# File 'lib/slimer/web.rb', line 80

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

#middlewaresObject



63
64
65
# File 'lib/slimer/web.rb', line 63

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

#set(attribute, value) ⇒ Object



88
89
90
# File 'lib/slimer/web.rb', line 88

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

#settingsObject

rubocop:enable Lint/MissingSuper



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

def settings
  self.class.settings
end

#use(*middleware_args, &block) ⇒ Object



59
60
61
# File 'lib/slimer/web.rb', line 59

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