Module: Dkdeploy::Helpers::Common

Defined in:
lib/dkdeploy/helpers/common.rb

Overview

common helpers, which are not task specific

Instance Method Summary collapse

Instance Method Details

#ask_array_variable(args, variable_name_symbol, question_selector, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/dkdeploy/helpers/common.rb', line 24

def ask_array_variable(args, variable_name_symbol, question_selector, &block)
  variable_content = ask_variable(args, variable_name_symbol, question_selector, &block)
  return variable_content if variable_content.is_a?(Array)
  return variable_content.split if variable_content.is_a?(String)

  raise(I18n.t('errors.variable_content_is_neither_string_nor_array', variable_name: variable_name_symbol, scope: :dkdeploy))
end

#ask_variable(args, variable_name_symbol, question_selector, &block) ⇒ Object



19
20
21
22
# File 'lib/dkdeploy/helpers/common.rb', line 19

def ask_variable(args, variable_name_symbol, question_selector, &block)
  ENV[variable_name_symbol.to_s.upcase] || args[variable_name_symbol] ||
    fetch(variable_name_symbol) || ask_via_terminal(question_selector, &block)
end

#ask_via_terminal(question_selector, &block) ⇒ Object



13
14
15
16
17
# File 'lib/dkdeploy/helpers/common.rb', line 13

def ask_via_terminal(question_selector, &block)
  question = I18n.t(question_selector, scope: :dkdeploy)
  answer = terminal.ask(question, &block)
  String.new(answer)
end

#terminalObject



9
10
11
# File 'lib/dkdeploy/helpers/common.rb', line 9

def terminal
  @terminal ||= HighLine.new
end