Class: KafoWizards::HighLine::Wizard
Instance Attribute Summary
#description, #entries, #header, #interactive, #logger, #renderers, #validators
Instance Method Summary
collapse
#buttons, default_renderers, #factory, #initialize, register_default_renderer, #run, #triggers, #update, #validate, #values
Instance Method Details
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 7
def
begin
choice = nil
loop do
say "\n"
say ::HighLine.color(, :yellow) unless .empty?
print_values
say "\n" + description
choice =
break unless choice.nil?
end
validate(values) if triggers.include? choice
choice
rescue KafoWizards::ValidationError => e
say ::HighLine.color("\nUnable to procedd due to following error(s):", :red)
say ::HighLine.color(format_errors(e.messages), :red)
say "\n"
retry
end
end
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 41
def
choose do ||
. = ::HighLine.color("\nAvailable actions", :white)
.prompt = 'Your choice: '
.select_by = :index
sorted_entries.each do |entry|
.choice(render_entry(entry)) do
begin
entry.call_pre_hook
res = render_action(entry)
entry.call_post_hook
res
rescue KafoWizards::ValidationError => e
say ::HighLine.color("\nValidation error: #{e.message}", :red)
say "Please, try again... \n\n"
retry
rescue Interrupt
nil
end
end
end
end
end
|
#print_values ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 28
def print_values
entries.each do |entry|
max_label_width = 25
next if (entry.class <= KafoWizards::Entries::ButtonEntry)
if entry.required?
label = ::HighLine.color(('*'+entry.label).rjust(max_label_width), :bold, :yellow)
else
label = entry.label.rjust(max_label_width)
end
say "#{label}: " + render_value(entry)
end
end
|
#render_action(entry) ⇒ Object
67
68
69
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 67
def render_action(entry)
call_renderer_for_entry(:render_action, entry)
end
|
#render_entry(entry) ⇒ Object
75
76
77
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 75
def render_entry(entry)
call_renderer_for_entry(:render_entry, entry)
end
|
#render_value(entry) ⇒ Object
71
72
73
|
# File 'lib/kafo_wizards/highline/wizard.rb', line 71
def render_value(entry)
call_renderer_for_entry(:render_value, entry)
end
|