summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-11-04 23:41:20 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-11-05 11:26:00 -0300
commit18c2eeb70714f06da79840b0b6c91c26f82adeee (patch)
treecbe0d4c94365bc7b4539e97c56865f5bdc12d65c
parent81d9ee76bd326069142a36dc8216594e47659963 (diff)
downloadhighline-18c2eeb70714f06da79840b0b6c91c26f82adeee.tar.gz
Move logic to Question
-rwxr-xr-xlib/highline/question.rb5
-rw-r--r--lib/highline/question_asker.rb9
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/highline/question.rb b/lib/highline/question.rb
index f93d4d1..f5d70bf 100755
--- a/lib/highline/question.rb
+++ b/lib/highline/question.rb
@@ -289,6 +289,11 @@ class HighLine
@internal_responses.merge(@user_responses)
end
+ def final_response(error)
+ response = final_responses[error]
+ response.call(answer) rescue response
+ end
+
#
# Returns the provided _answer_string_ after changing character case by
# the rules of this Question. Valid settings for whitespace are:
diff --git a/lib/highline/question_asker.rb b/lib/highline/question_asker.rb
index 52f4959..03b3ff7 100644
--- a/lib/highline/question_asker.rb
+++ b/lib/highline/question_asker.rb
@@ -114,16 +114,11 @@ class HighLine
private
## Delegate to Highline
- def explain_error(error)
- @highline.say(error_final_response(error)) if error
+ def explain_error(explanation_key) # eg: :not_valid, :not_in_range
+ @highline.say(question.final_response(explanation_key))
@highline.say(question.ask_on_error_msg)
end
- def error_final_response(error)
- final_response = question.final_responses[error]
- final_response.call(question.answer) rescue final_response
- end
-
def gather_with_array
[].tap do |answers|
answers << ask_once