Class: Codewars::Configuration
- Inherits:
-
Object
- Object
- Codewars::Configuration
- Defined in:
- lib/codewars/configuration.rb
Constant Summary collapse
- CONFIG_NAME =
'.codewarsrc'.freeze
Class Method Summary collapse
- .config ⇒ Object
- .config_path ⇒ Object
- .option(option) ⇒ Object
- .write_option_to_config(option, value) ⇒ Object
Class Method Details
.config ⇒ Object
16 17 18 |
# File 'lib/codewars/configuration.rb', line 16 def self.config File.exist?(config_path) ? YAML.load_file(config_path) : {} end |
.config_path ⇒ Object
20 21 22 |
# File 'lib/codewars/configuration.rb', line 20 def self.config_path "#{ENV['HOME']}/#{CONFIG_NAME}" end |
.option(option) ⇒ Object
24 25 26 |
# File 'lib/codewars/configuration.rb', line 24 def self.option(option) config[option] end |
.write_option_to_config(option, value) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/codewars/configuration.rb', line 7 def self.write_option_to_config(option, value) config_hash = config config_hash[option] = value config_str = '' config_hash.each { |k, v| config_str += "#{k}: #{v}\n" } File.write(config_path, config_str) end |