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
|