Class: TTY::Prompt::Evaluator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/prompt/evaluator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Evaluates provided parameters and stops if any of them fails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(question, &block) ⇒ Evaluator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Evaluator.



12
13
14
15
16
# File 'lib/tty/prompt/evaluator.rb', line 12

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

Instance Attribute Details

#resultsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/tty/prompt/evaluator.rb', line 10

def results
  @results
end

Instance Method Details

#call(initial) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
# File 'lib/tty/prompt/evaluator.rb', line 18

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

#check(proc = nil, &block) ⇒ Object Also known as: <<

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/tty/prompt/evaluator.rb', line 23

def check(proc = nil, &block)
  results << (proc || block)
end