Module: Bovem::ConsoleMethods::Interactions

Extended by:
ActiveSupport::Concern
Included in:
Bovem::Console
Defined in:
lib/bovem/console.rb

Overview

Methods to interact with the user and other processes.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#read(prompt = true, default_value = nil, validator = nil, echo = true) ⇒ Object

Reads a string from the console.



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/bovem/console.rb', line 469

def read(prompt = true, default_value = nil, validator = nil, echo = true)
  prompt = sanitize_prompt(prompt)

  # Adjust validator
  validator = sanitize_validator(validator)

  with_echo_handling(echo) do
    begin
      catch(:reply) do
        while true do
          reply = validate_input_value(read_input_value(prompt, default_value), validator)
          handle_reply(reply)
        end
      end
    rescue Interrupt => e
      default_value
    end
  end
end

#task(message = nil, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, block_indentation = 2, block_indentation_absolute = false) ⇒ Symbol

Executes a block of code in a indentation region and then prints out and ending status message.



501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/bovem/console.rb', line 501

def task(message = nil, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, block_indentation = 2, block_indentation_absolute = false)
  status = nil

  self.begin(message, suffix, indent, wrap, plain, indented_banner, full_colored) if message.present?
  self.with_indentation(block_indentation, block_indentation_absolute) do
    rv = block_given? ? yield.ensure_array : [:ok] # Execute block
    exit_task(message, rv, plain) # Handle task exit
    status = rv[0] # Return value

  end

  status
end