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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/aws_assume_role/ui.rb', line 40
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
32
33
34
|
# File 'lib/aws_assume_role/ui.rb', line 32
def error(text)
puts pastel.red(text)
end
|
21
22
23
|
# File 'lib/aws_assume_role/ui.rb', line 21
def input
@input ||= HighLine.new($stdin, $stderr)
end
|
.out(text) ⇒ Object
13
14
15
|
# File 'lib/aws_assume_role/ui.rb', line 13
def out(text)
puts text
end
|
.pastel ⇒ Object
17
18
19
|
# File 'lib/aws_assume_role/ui.rb', line 17
def pastel
@pastel ||= Pastel.new
end
|
.show_validation_errors(result) ⇒ Object
36
37
38
|
# File 'lib/aws_assume_role/ui.rb', line 36
def show_validation_errors(result)
error validation_errors_to_s(result)
end
|
.t(*options) ⇒ Object
54
55
56
|
# File 'lib/aws_assume_role/ui.rb', line 54
def t(*options)
::I18n.t(options).first
end
|
.validation_errors_to_s(result) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/aws_assume_role/ui.rb', line 25
def validation_errors_to_s(result)
text = result.errors.keys.map do |k|
result.errors[k].join(";")
end.join(" ")
text
end
|