Sha256: b5a4a88430905dca59429b75f8fb172451bf498876da2715b3b727a93ba1706c

Contents?: true

Size: 630 Bytes

Versions: 8

Compression:

Stored size: 630 Bytes

Contents

# encoding: utf-8

require_relative '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

8 entries across 8 versions & 2 rubygems

Version Path
tty-prompt-0.15.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.14.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.13.2 lib/tty/prompt/evaluator.rb
tty-prompt-0.13.1 lib/tty/prompt/evaluator.rb
tty-prompt-0.13.0 lib/tty/prompt/evaluator.rb
austb-tty-prompt-0.13.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.12.0 lib/tty/prompt/evaluator.rb
tty-prompt-0.11.0 lib/tty/prompt/evaluator.rb