Module: ThorActionsExtend

Includes:
Thor::Actions
Included in:
DockerizeStack::Command
Defined in:
lib/thor_extend.rb

Constant Summary collapse

CONFIG =
JSON.parse(
  JSON.dump(YAML.load_file("#{File.dirname(__FILE__)}/config.yml")),
  symbolize_names: true
)

Instance Method Summary collapse

Instance Method Details

#fetch_template_variablesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/thor_extend.rb', line 24

def fetch_template_variables
  @config[:questions].each do |question|
    default = question[:default]
    option = question[:option]
    title = question[:title]
    type = question[:type]

    if @options[option] || @options[option] == false
      instance_variable_set("@#{option}", @options[option])
      next
    end

    case type
    when 'with_default'
      instance_variable_set("@#{option}", default)
    when 'ask_with_default'
      result = ask(title)
      result == '' ? default : result

      instance_variable_set("@#{option}", result)
    when 'ask_with_default_boolean'
      result = ask(title)
      result = default if result == ''
      result = %w[yes y true].include?(result) ? true : false

      instance_variable_set("@#{option}", result)
    when 'ask_with_options'
      instance_variable_set("@#{option}", ask(title, limited_to: question[:ask_options]))
    else
      raise "Invalid question type: #{type}"
    end
  end
end

#run(options, template_type) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/thor_extend.rb', line 14

def run(options, template_type)
  @template_type = template_type
  @options = options
  @output_folder = options['output_folder']
  @config = CONFIG[@template_type]
  self.class.source_root(template_type_path)

  fetch_template_variables
end