Module: Richard::ConfigRepository
- Extended by:
- ConfigRepository
- Included in:
- ConfigRepository
- Defined in:
- lib/richard/config_repository.rb
Instance Method Summary collapse
Instance Method Details
#find_or_create ⇒ Object
8 9 10 |
# File 'lib/richard/config_repository.rb', line 8 def find_or_create load || prompt end |
#load ⇒ Object
30 31 32 33 34 |
# File 'lib/richard/config_repository.rb', line 30 def load return YAML.load_file(Config::CONFIG_FILE) rescue Errno::ENOENT => e return false end |
#prompt ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/richard/config_repository.rb', line 12 def prompt puts "Could not find a valid config file. Creating one at #{Config::CONFIG_FILE}" url = ask "URL for Richard: " do |q| q.default = Richard::Config::DEFAULT_URL end api_key = ask "API Key: " do |q| q.validate = /\w+/ end config = Config.new(url, api_key) save(config) return config end |
#save(config) ⇒ Object
36 37 38 39 40 |
# File 'lib/richard/config_repository.rb', line 36 def save(config) File.open(Config::CONFIG_FILE, 'w') do |file| file.write(YAML.dump(config)) end end |