Module: Safeconsole::Messages
- Included in:
- Console, SessionWatcher
- Defined in:
- lib/safeconsole/messages.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .app_name ⇒ Object
- .commands ⇒ Object
- .commit ⇒ Object
- .done ⇒ Object
- .included(base) ⇒ Object
- .invalid_query ⇒ Object
- .method_missing(method) ⇒ Object
- .nevermind ⇒ Object
- .refresh ⇒ Object
- .respond_to_missing?(_name, _include_private) ⇒ Boolean
- .session_expired ⇒ Object
- .session_start ⇒ Object
- .session_stats ⇒ Object
- .transaction_start ⇒ Object
- .unsafe_env ⇒ Object
- .welcome ⇒ Object
Class Method Details
.app_name ⇒ Object
25 26 27 28 |
# File 'lib/safeconsole/messages.rb', line 25 def app_name a = Artii::Base.new font: "slant" a.asciify(Safeconsole.config.app_name) end |
.commands ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/safeconsole/messages.rb', line 41 def commands <<~MSG Usage: - refresh: Load a new transaction (and commit if configured) - commit: Set this transaction to be commited to the DB on refresh/exit - nevermind: Set this transaction to be *discarded* on refresh/exit - stats: Print the current transaction and session stats (commit status, length, stats) - commands: Print command instructions again Hotkeys: - ctrl+d: Load a new transaction (equivilent to refresh) MSG end |
.commit ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/safeconsole/messages.rb', line 71 def commit <<~MSG This transaction will now be commited to the database on refresh/exit If this was a mistake, run the command: nevermind MSG end |
.done ⇒ Object
95 96 97 |
# File 'lib/safeconsole/messages.rb', line 95 def done "You've located the lost artifact!" end |
.included(base) ⇒ Object
5 6 7 |
# File 'lib/safeconsole/messages.rb', line 5 def self.included(base) base.extend ClassMethods end |
.invalid_query ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/safeconsole/messages.rb', line 103 def invalid_query <<~MSG Active Record Error! Oops! Looks like you executed an invalid SQL query. This breaks the current transaction. All ActiveRecord based interactions will be broken now. Grab a new transaction with the command: refresh MSG end |
.method_missing(method) ⇒ Object
19 20 21 |
# File 'lib/safeconsole/messages.rb', line 19 def self.method_missing(method) "**** Unknown Message #{method} ****" end |
.nevermind ⇒ Object
79 80 81 |
# File 'lib/safeconsole/messages.rb', line 79 def nevermind "Transaction changes will be discarded on refresh/exit" end |
.refresh ⇒ Object
91 92 93 |
# File 'lib/safeconsole/messages.rb', line 91 def refresh "Your magic is running low. You stop casting to drink a potion, restoring your energy." end |
.respond_to_missing?(_name, _include_private) ⇒ Boolean
15 16 17 |
# File 'lib/safeconsole/messages.rb', line 15 def self.respond_to_missing?(_name, _include_private) true end |
.session_expired ⇒ Object
99 100 101 |
# File 'lib/safeconsole/messages.rb', line 99 def session_expired "You've been searching for too long. The artifact is lost forever." end |
.session_start ⇒ Object
83 84 85 |
# File 'lib/safeconsole/messages.rb', line 83 def session_start "You're a wizard, searching for a long lost artifact." end |
.session_stats ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/safeconsole/messages.rb', line 56 def session_stats session_length = (Time.now - SessionWatcher.initialized_at).round minutes, seconds = session_length.divmod(50) <<~MSG Session: Length: #{minutes} minutes #{seconds} seconds Commands: #{SessionWatcher.total_commands} Transaction: Commit: #{Console.__console_commit} Commands: #{SessionWatcher.transaction_commands} MSG end |
.transaction_start ⇒ Object
87 88 89 |
# File 'lib/safeconsole/messages.rb', line 87 def transaction_start "You begin casting a locating spell" end |
.unsafe_env ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/safeconsole/messages.rb', line 114 def unsafe_env <<~MSG SAFECONSOLE WARNING Safeconsole is configured to not allow unsafe consoles for the current environment: #{Safeconsole.env} This session will now exit. If this is a mistake, check your safeconsole configuration MSG end |
.welcome ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/safeconsole/messages.rb', line 30 def welcome <<~MSG #{app_name} Current Rails Env: #{Safeconsole.config.current_env} Welcome to safeconsole, you're in good hands. MSG end |