Sha256: 50129330be45a65e2742d4f2a85dde6c51cd139aea99088398959abe594fa1c7
Contents?: true
Size: 898 Bytes
Versions: 17
Compression:
Stored size: 898 Bytes
Contents
# frozen_string_literal: true module TTY class Prompt # Accumulates errors class Result attr_reader :question, :value, :errors def initialize(question, value, errors = []) @question = question @value = value @errors = errors end def with(condition = nil, &block) validator = (condition || block) (new_value, validation_error) = validator.call(question, value) accumulated_errors = errors + Array(validation_error) if accumulated_errors.empty? Success.new(question, new_value) else Failure.new(question, new_value, accumulated_errors) end end def success? is_a?(Success) end def failure? is_a?(Failure) end class Success < Result end class Failure < Result end end end # Prompt end # TTY
Version data entries
17 entries across 17 versions & 3 rubygems