diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 01:02:26 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 01:02:26 -0300 |
commit | 10ddd179168f3fa447cff120b60cf7edfff46c10 (patch) | |
tree | 0598f710ae9375387a400128c2cd5950d421575f | |
parent | dd406657ead08e38d496107a704547dc8086fd0d (diff) | |
download | highline-10ddd179168f3fa447cff120b60cf7edfff46c10.tar.gz |
Extract Question#confirm_question
-rwxr-xr-x | lib/highline.rb | 12 | ||||
-rwxr-xr-x | lib/highline/question.rb | 12 |
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index 65845e1..e787629 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -540,16 +540,8 @@ class HighLine # need to add a layer of scope to ask a question inside a # question, without destroying instance data context_change = new_scope - if question.confirm == true - confirm_question = "Are you sure? " - else - # evaluate ERb under initial scope, so it will have - # access to question and answer - template = ERB.new(question.confirm, nil, "%") - template_renderer = TemplateRenderer.new(template, question, self) - confirm_question = template_renderer.render - end - raise NoConfirmationQuestionError unless context_change.agree(confirm_question) + + raise NoConfirmationQuestionError unless context_change.agree(question.confirm_question(self)) end else raise NotInRangeQuestionError diff --git a/lib/highline/question.rb b/lib/highline/question.rb index c03fb5c..948383d 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -495,6 +495,18 @@ class HighLine return highline.ask_once(self) end + def confirm_question(highline) + if confirm == true + "Are you sure? " + else + # evaluate ERb under initial scope, so it will have + # access to question and answer + template = ERB.new(confirm, nil, "%") + template_renderer = TemplateRenderer.new(template, self, highline) + template_renderer.render + end + end + private # |