Sha256: 7c7f7514dd80fab24b79db58401f64f13baeceb10c19d0976dc81f9d27f901fa

Contents?: true

Size: 859 Bytes

Versions: 4

Compression:

Stored size: 859 Bytes

Contents

# frozen_string_literal: true

module Roro
  module Configurators
    class QuestionAsker < Thor

      include Thor::Actions

      no_commands do
        def override_default(question)
          prompt = "Please supply a value:"
          answer = ask([question, prompt].join("\n"))
          answer.size > 1 ? answer : override_default(question)
        end

        def confirm_default(question)
          options = { "y": "yes", "n": "no"}
          humanized_options = options.map {|key, value|
            "(#{key}) #{value}"
          }
          getsome = "Would you like to accept the default value?\n"
          prompt = [question, getsome, humanized_options, "\n"].join("\n")
          answer = ask(prompt, limited_to: options.keys.map(&:to_s))
          answer.eql?('n') ? override_default(question) : 'y'
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roro-0.3.27 lib/roro/configurators/question_asker.rb
roro-0.3.25 lib/roro/configurators/question_asker.rb
roro-0.3.24 lib/roro/configurators/question_asker.rb
roro-0.3.23 lib/roro/configurators/question_asker.rb