lib/tty/prompt/converters.rb in tty-prompt-0.3.0 vs lib/tty/prompt/converters.rb in tty-prompt-0.4.0

- old
+ new

@@ -15,13 +15,19 @@ Converters.converter_registry end end end + def self.on_error + yield + rescue Necromancer::ConversionTypeError => e + raise ConversionError, e.message + end + converter(:bool) do |input| converter = Necromancer.new - converter.convert(input).to(:boolean, strict: true) + on_error { converter.convert(input).to(:boolean, strict: true) } end converter(:string) do |input| String(input).chomp end @@ -30,30 +36,30 @@ input.to_sym end converter(:date) do |input| converter = Necromancer.new - converter.convert(input).to(:date) + on_error { converter.convert(input).to(:date, strict: true) } end converter(:datetime) do |input| converter = Necromancer.new - converter.convert(input).to(:datetime) + on_error { converter.convert(input).to(:datetime, strict: true) } end converter(:int) do |input| converter = Necromancer.new - converter.convert(input).to(:integer) + on_error { converter.convert(input).to(:integer, strict: true) } end converter(:float) do |input| converter = Necromancer.new - converter.convert(input).to(:float) + on_error { converter.convert(input).to(:float, strict: true) } end converter(:range) do |input| converter = Necromancer.new - converter.convert(input).to(:range, strict: true) + on_error { converter.convert(input).to(:range, strict: true) } end converter(:regexp) do |input| Regexp.new(input) end