Class: CodeownerValidator::ConfigHelper
- Inherits:
-
Object
- Object
- CodeownerValidator::ConfigHelper
- Defined in:
- lib/codeowner_validator/helpers/config_helper.rb
Overview
Public: A configuration helper designed to assist in simple abstraction of TTY:Prompt requests and assign those responses to the base module’s configuration
Class Method Summary collapse
-
.ask(ident:, prompt:, required: false, force_ask: false, mask: false, **args) ⇒ Object
Public: An abstraction onto the TTY:Prompt.ask to allow requesting information from the user’s input and saving that input within the base module’s configuration.
-
.select(ident:, prompt:, force_ask: false, choices:, **args) ⇒ Object
Public: An abstraction onto the TTY:Prompt.select to allow requesting information from the user’s input and saving that input within the base module’s configuration.
Class Method Details
.ask(ident:, prompt:, required: false, force_ask: false, mask: false, **args) ⇒ Object
Public: An abstraction onto the TTY:Prompt.ask to allow requesting information from the user’s input and saving that input within the base module’s configuration
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/codeowner_validator/helpers/config_helper.rb', line 21 def ask(ident:, prompt:, required: false, force_ask: false, mask: false, **args) opts = {}.tap do |h| h[:required] = required h[:default] = args[:default] if args[:default] end # return if either not being forced to ask or the information has been previously captured return if !force_ask && ::CodeownerValidator.respond_to?(ident) tty_prompt = ::TTY::Prompt.new response = tty_prompt.collect do if mask key(ident.to_sym).mask( prompt, opts ) else key(ident.to_sym).ask( prompt, opts ) end end ::CodeownerValidator.configure! response end |
.select(ident:, prompt:, force_ask: false, choices:, **args) ⇒ Object
Public: An abstraction onto the TTY:Prompt.select to allow requesting information from the user’s input and saving that input within the base module’s configuration
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/codeowner_validator/helpers/config_helper.rb', line 58 def select(ident:, prompt:, force_ask: false, choices:, **args) # return if either not being forced to ask or the information has been previously captured return if !force_ask && ::CodeownerValidator.respond_to?(ident) tty_prompt = ::TTY::Prompt.new response = tty_prompt.select( prompt, choices, args ) ::CodeownerValidator.configure! ident => response end |