Class: Safeconsole::SessionWatcher
- Inherits:
-
Object
- Object
- Safeconsole::SessionWatcher
- Includes:
- Messages, Singleton
- Defined in:
- lib/safeconsole/session_watcher.rb
Class Attribute Summary collapse
-
.initialized_at ⇒ Object
Returns the value of attribute initialized_at.
-
.last_command_at ⇒ Object
Returns the value of attribute last_command_at.
-
.total_commands ⇒ Object
Returns the value of attribute total_commands.
-
.transaction_commands ⇒ Object
Returns the value of attribute transaction_commands.
Class Method Summary collapse
- .command_ran ⇒ Object
- .session_limit_reached? ⇒ Boolean
- .timeout_reached? ⇒ Boolean
- .watch_session! ⇒ Object
Methods included from Messages
app_name, commands, commit, done, included, invalid_query, method_missing, nevermind, refresh, respond_to_missing?, session_expired, session_start, session_stats, transaction_start, unsafe_env, welcome
Class Attribute Details
.initialized_at ⇒ Object
Returns the value of attribute initialized_at.
14 15 16 |
# File 'lib/safeconsole/session_watcher.rb', line 14 def initialized_at @initialized_at end |
.last_command_at ⇒ Object
Returns the value of attribute last_command_at.
14 15 16 |
# File 'lib/safeconsole/session_watcher.rb', line 14 def last_command_at @last_command_at end |
.total_commands ⇒ Object
Returns the value of attribute total_commands.
14 15 16 |
# File 'lib/safeconsole/session_watcher.rb', line 14 def total_commands @total_commands end |
.transaction_commands ⇒ Object
Returns the value of attribute transaction_commands.
14 15 16 |
# File 'lib/safeconsole/session_watcher.rb', line 14 def transaction_commands @transaction_commands end |
Class Method Details
.command_ran ⇒ Object
16 17 18 19 20 |
# File 'lib/safeconsole/session_watcher.rb', line 16 def command_ran @total_commands += 1 @transaction_commands += 1 @last_command_at = Time.now end |
.session_limit_reached? ⇒ Boolean
36 37 38 39 40 |
# File 'lib/safeconsole/session_watcher.rb', line 36 def session_limit_reached? return false unless Safeconsole.config.session_timeout @initialized_at < Safeconsole.config.session_timeout.ago end |
.timeout_reached? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/safeconsole/session_watcher.rb', line 42 def timeout_reached? return false unless Safeconsole.config.command_timeout last_command_at < Safeconsole.config.command_timeout.ago end |
.watch_session! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/safeconsole/session_watcher.rb', line 22 def watch_session! Thread.start do loop do if timeout_reached? || session_limit_reached? (:session_expired) Console.__console_commit = false break binding.eval("exit") end sleep 2 end end end |