class Capistrano::Configuration::Question
Attributes
default[R]
key[R]
options[R]
Public Class Methods
new(key, default, options={})
click to toggle source
# File lib/capistrano/configuration/question.rb, line 4 def initialize(key, default, options={}) @key = key @default = default @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 10 def call ask_question value_or_default end
Private Instance Methods
ask_question()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 19 def ask_question $stdout.print question $stdout.flush end
echo?()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 63 def echo? (options || {}).fetch(:echo, true) end
gets()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 38 def gets return unless stdin.tty? if echo? stdin.gets else stdin.noecho(&:gets).tap { $stdout.print "\n" } end rescue Errno::EIO # when stdio gets closed return end
prompt()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 71 def prompt (options || {}).fetch(:prompt, nil) end
question()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 51 def question if prompt && default.nil? I18n.t(:question_prompt, key: prompt, scope: :capistrano) elsif prompt I18n.t(:question_prompt_default, key: prompt, default_value: default, scope: :capistrano) elsif default.nil? I18n.t(:question, key: key, scope: :capistrano) else I18n.t(:question_default, key: key, default_value: default, scope: :capistrano) end end
response()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 32 def response return @response if defined? @response @response = (gets || "").chomp end
stdin()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 67 def stdin (options || {}).fetch(:stdin, $stdin) end
value_or_default()
click to toggle source
# File lib/capistrano/configuration/question.rb, line 24 def value_or_default if response.empty? default else response end end