Class: Pgchief::Prompt::Base
- Inherits:
-
Object
- Object
- Pgchief::Prompt::Base
- Defined in:
- lib/pgchief/prompt/base.rb
Overview
Base class for prompt classes
Direct Known Subclasses
BackupDatabase, CreateDatabase, CreateUser, DatabaseManagement, DropDatabase, DropUser, GrantDatabasePrivileges, RestoreDatabase, Start, UserManagement, ViewDatabaseConnectionString
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(*params) ⇒ Base
constructor
A new instance of Base.
- #klassify(scope, words) ⇒ Object
- #prompt ⇒ Object
-
#yes_or_no(question, yes: nil, no: nil) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Constructor Details
#initialize(*params) ⇒ Base
Returns a new instance of Base.
13 14 15 |
# File 'lib/pgchief/prompt/base.rb', line 13 def initialize(*params) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/pgchief/prompt/base.rb', line 11 def params @params end |
Class Method Details
.call(*params) ⇒ Object
7 8 9 |
# File 'lib/pgchief/prompt/base.rb', line 7 def self.call(*params) new(*params).call end |
Instance Method Details
#call ⇒ Object
17 18 19 |
# File 'lib/pgchief/prompt/base.rb', line 17 def call raise NotImplementedError end |
#klassify(scope, words) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/pgchief/prompt/base.rb', line 21 def klassify(scope, words) Object.const_get([ 'Pgchief', '::', scope.capitalize, '::', words.split.map(&:capitalize) ].flatten.join) end |
#prompt ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pgchief/prompt/base.rb', line 33 def prompt @prompt ||= TTY::Prompt.new.tap do |p| p.on(:keypress) do |event| p.trigger(:keydown) if event.value == 'j' p.trigger(:keyup) if event.value == 'k' end p.on(:keyescape) do p.say "\n\nExiting...bye-bye 👋\n\n" exit end end end |
#yes_or_no(question, yes: nil, no: nil) ⇒ Object
rubocop:disable Naming/MethodParameterName
28 29 30 31 |
# File 'lib/pgchief/prompt/base.rb', line 28 def yes_or_no(question, yes: nil, no: nil) # rubocop:disable Naming/MethodParameterName response = prompt.yes?(question) response ? yes&.call : no&.call end |