Class: TTY::MyPrompt
- Inherits:
-
Prompt
- Object
- Prompt
- TTY::MyPrompt
- Defined in:
- lib/clir/TTY-Prompt.cls.rb
Constant Summary collapse
Class Attribute Summary collapse
-
.mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
-
.set_mode_interactive ⇒ Object
Methods to switch hardly in interactive mode during tests.
- .unset_mode_interactive ⇒ Object (also: set_mode_inputs)
Instance Method Summary collapse
-
#default_name_for_value(choices_list, default_value) ⇒ Object
Sadly, for select, Tty-prompt requires the :name value for the default value (:default) in methods.
- #include_methods_by_mode(interactive_mode) ⇒ Object
-
#init(mode_interactive = nil) ⇒ Object
Init Q instance.
-
#toggle_mode ⇒ Object
Méthode qui fait basculer du mode normal au mode test et inversement.
Class Attribute Details
.mode ⇒ Object
Returns the value of attribute mode.
30 31 32 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 30 def mode @mode end |
Class Method Details
.set_mode_interactive ⇒ Object
Methods to switch hardly in interactive mode during tests
33 34 35 36 37 38 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 33 def set_mode_interactive Object.send(:remove_const, 'Q') Object.const_set('Q', new) Q.init(mode_interactive = true) File.write(MARKER_TTY_FILE,"#{Time.now}::true") end |
.unset_mode_interactive ⇒ Object Also known as: set_mode_inputs
39 40 41 42 43 44 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 39 def unset_mode_interactive Object.send(:remove_const, 'Q') Object.const_set('Q', new) File.delete(MARKER_TTY_FILE) if File.exist?(MARKER_TTY_FILE) Q.init(mode_interactive = false) end |
Instance Method Details
#default_name_for_value(choices_list, default_value) ⇒ Object
Sadly, for select, Tty-prompt requires the :name value for the default value (:default) in methods. This method can return :name valeur from :value
100 101 102 103 104 105 106 107 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 100 def default_name_for_value(choices_list, default_value) choices_list.each do |dchoix| if dchoix[:value] == default_value return dchoix[:name] end end return nil end |
#include_methods_by_mode(interactive_mode) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 74 def include_methods_by_mode(interactive_mode) if interactive_mode # # Usual methods # (overwrite tests method if any) # self.extend ReplayedTTYMethods else # # Use Inputs methods instead of usual methods # (overwrite them) # self.extend InputsTTYMethods end @mode = interactive_mode ? :interactive : :inputs self.class.mode = @mode end |
#init(mode_interactive = nil) ⇒ Object
Init Q instance
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/clir/TTY-Prompt.cls.rb', line 55 def init(mode_interactive = nil) if File.exist?(MARKER_TTY_FILE) _, mode_interactive = File.read(MARKER_TTY_FILE).split('::') mode_interactive = eval(mode_interactive) include_methods_by_mode(mode_interactive) elsif mode_interactive === nil toggle_mode else include_methods_by_mode(mode_interactive) end @inputs = nil # for testing end |