Class: Prompts::Form
- Inherits:
-
Object
- Object
- Prompts::Form
- Defined in:
- lib/prompts/form.rb
Class Method Summary collapse
Instance Method Summary collapse
- #confirm(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
- #content {|@content| ... } ⇒ Object
-
#initialize ⇒ Form
constructor
A new instance of Form.
- #pause(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
- #select(label: nil, options: nil, prompt: "> ", hint: nil, default: nil, validate: nil, name: nil) {|prompt| ... } ⇒ Object
- #submit ⇒ Object
- #text(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
Constructor Details
Class Method Details
.submit {|instance| ... } ⇒ Object
5 6 7 8 9 |
# File 'lib/prompts/form.rb', line 5 def self.submit(&block) instance = new yield instance if block instance.submit end |
Instance Method Details
#confirm(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/prompts/form.rb', line 47 def confirm(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block) prompt = ConfirmPrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate) yield(prompt) if block prepend_form_content_to_prompt(prompt) key = name || (@index += 1) @prompts[key] = prompt end |
#content {|@content| ... } ⇒ Object
18 19 20 21 |
# File 'lib/prompts/form.rb', line 18 def content(&block) yield @content @content end |
#pause(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/prompts/form.rb', line 39 def pause(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block) prompt = PausePrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate) yield(prompt) if block prepend_form_content_to_prompt(prompt) key = name || (@index += 1) @prompts[key] = prompt end |
#select(label: nil, options: nil, prompt: "> ", hint: nil, default: nil, validate: nil, name: nil) {|prompt| ... } ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/prompts/form.rb', line 31 def select(label: nil, options: nil, prompt: "> ", hint: nil, default: nil, validate: nil, name: nil, &block) prompt = SelectPrompt.new(label: label, options: , prompt: prompt, hint: hint, default: default, validate: validate) yield(prompt) if block prepend_form_content_to_prompt(prompt) key = name || (@index += 1) @prompts[key] = prompt end |
#submit ⇒ Object
55 56 57 58 59 60 |
# File 'lib/prompts/form.rb', line 55 def submit @prompts.each do |key, prompt| @results[key] = prompt.ask end @results end |
#text(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil) {|prompt| ... } ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/prompts/form.rb', line 23 def text(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block) prompt = TextPrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate) yield(prompt) if block prepend_form_content_to_prompt(prompt) key = name || (@index += 1) @prompts[key] = prompt end |