Module: AwsAssumeRole::Ui
Constant Summary
Config, DefaultProvider, VERSION
Class Method Summary
collapse
shared_config
Class Method Details
.ask_with_validation(variable_name, question, type: Dry::Types["coercible.string"], &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/aws_assume_role/ui.rb', line 38
def ask_with_validation(variable_name, question, type: Dry::Types["coercible.string"], &block)
STDOUT.puts pastel.yellow question
validator = Dry::Validation.Schema do
configure do
config.messages = :i18n
end
required(variable_name) { instance_eval(&block) }
end
result = validator.call(variable_name => type[(STDIN.gets || "").chomp])
return result.to_h[variable_name] if result.success?
show_validation_errors result
ask_with_validation variable_name, question, &block
end
|
.error(text) ⇒ Object
30
31
32
|
# File 'lib/aws_assume_role/ui.rb', line 30
def error(text)
puts pastel.red(text)
end
|
19
20
21
|
# File 'lib/aws_assume_role/ui.rb', line 19
def input
@input ||= HighLine.new
end
|
.out(text) ⇒ Object
11
12
13
|
# File 'lib/aws_assume_role/ui.rb', line 11
def out(text)
puts text
end
|
.pastel ⇒ Object
15
16
17
|
# File 'lib/aws_assume_role/ui.rb', line 15
def pastel
@pastel ||= Pastel.new
end
|
.show_validation_errors(result) ⇒ Object
34
35
36
|
# File 'lib/aws_assume_role/ui.rb', line 34
def show_validation_errors(result)
error validation_errors_to_s(result)
end
|
.t(*options) ⇒ Object
52
53
54
|
# File 'lib/aws_assume_role/ui.rb', line 52
def t(*options)
::I18n.t(options).first
end
|
.validation_errors_to_s(result) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/aws_assume_role/ui.rb', line 23
def validation_errors_to_s(result)
text = result.errors.keys.map do |k|
result.errors[k].join(";")
end.join(" ")
text
end
|