class Rubiclifier::Setting
Attributes
explanation[R]
is_secret[R]
key[R]
label[R]
nullable[R]
Public Class Methods
new(key, label, explanation: nil, is_secret: false, nullable: false)
click to toggle source
# File lib/setting.rb, line 6 def initialize(key, label, explanation: nil, is_secret: false, nullable: false) @key = key @label = label @explanation = explanation @is_secret = is_secret @nullable = nullable end
Public Instance Methods
explanation_text()
click to toggle source
# File lib/setting.rb, line 32 def explanation_text if explanation.is_a?(Proc) "(#{explanation.call}) " elsif explanation "(#{explanation}) " end end
is_setup?()
click to toggle source
# File lib/setting.rb, line 40 def is_setup? DB.get_setting(key) || nullable end
populate()
click to toggle source
# File lib/setting.rb, line 14 def populate input = nil loop do print("What's the #{label}? #{explanation_text}".blue) input = if is_secret STDIN.noecho(&:gets).chomp.tap { puts } else STDIN.gets.chomp end if input == "" input = nil puts("This value can't be empty.".red) unless nullable end break if input || nullable end DB.save_setting(key, input, is_secret: is_secret) unless input.nil? end