Class: ServerTiming::Auth
- Inherits:
-
Object
- Object
- ServerTiming::Auth
- Defined in:
- lib/server_timing/auth.rb
Overview
Encapsulates logic that determines whether the user is properly authorized to view server timing response headers.
Class Method Summary collapse
- .deny! ⇒ Object
- .ok! ⇒ Object
- .permitted? ⇒ Boolean
- .reset! ⇒ Object
-
.state ⇒ Object
Can be one of three values: * true * false * nil (default).
- .state=(new_state) ⇒ Object
Class Method Details
.deny! ⇒ Object
8 9 10 |
# File 'lib/server_timing/auth.rb', line 8 def self.deny! self.state=false end |
.ok! ⇒ Object
4 5 6 |
# File 'lib/server_timing/auth.rb', line 4 def self.ok! self.state=true end |
.permitted? ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/server_timing/auth.rb', line 28 def self.permitted? if state return true elsif state.is_a?(FalseClass) return false else # implied access - state has not been set # If not Rails, return true return true if !ServerTiming.rails? # If in a non-production environment, permit return true if !Rails.env.production? # In production, return false if no state has been set return false if Rails.env.production? end end |
.reset! ⇒ Object
12 13 14 |
# File 'lib/server_timing/auth.rb', line 12 def self.reset! self.state=nil end |
.state ⇒ Object
Can be one of three values:
-
true
-
false
-
nil (default)
24 25 26 |
# File 'lib/server_timing/auth.rb', line 24 def self.state Thread.current[:server_timing_authorized] end |
.state=(new_state) ⇒ Object
16 17 18 |
# File 'lib/server_timing/auth.rb', line 16 def self.state=(new_state) Thread.current[:server_timing_authorized] = new_state end |