Sha256: 06cc5616ef7641783bf59a61b7e93db5a7f2aa1d473fd05c28da395017a59c53

Contents?: true

Size: 632 Bytes

Versions: 10

Compression:

Stored size: 632 Bytes

Contents

# encoding: utf-8

require 'tty/prompt/result'

module TTY
  class Prompt
    # Evaluates provided parameters and stops if any of them fails
    # @api private
    class Evaluator
      attr_reader :results

      def initialize(question, &block)
        @question = question
        @results = []
        instance_eval(&block) if block
      end

      def call(initial)
        seed = Result::Success.new(@question, initial)
        results.reduce(seed, &:with)
      end

      def check(proc = nil, &block)
        results << (proc || block)
      end
      alias_method :<<, :check
    end # Evaluator
  end # Prompt
end # TTY

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tty-prompt-0.10.1 lib/tty/prompt/evaluator.rb
tty-prompt-0.10.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.9.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.8.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.7.1 lib/tty/prompt/evaluator.rb
tty-prompt-0.7.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.6.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.5.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.4.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.3.0 lib/tty/prompt/evaluator.rb