Class: Uffizzi::ConfigFile
- Inherits:
-
Object
- Object
- Uffizzi::ConfigFile
- Defined in:
- lib/uffizzi/config_file.rb
Constant Summary collapse
- CONFIG_DIR =
"#{Dir.home}/.config/uffizzi"
- CONFIG_PATH =
"#{Dir.home}/.config/uffizzi/config_default.json"
Class Method Summary collapse
- .config_path ⇒ Object
- .delete ⇒ Object
- .exists? ⇒ Boolean
- .list ⇒ Object
- .option_exists?(option) ⇒ Boolean
- .option_has_value?(option) ⇒ Boolean
- .read_option(option, nested_option = nil) ⇒ Object
- .rewrite_cookie(cookie) ⇒ Object
- .unset_option(key) ⇒ Object
- .write_option(key, value) ⇒ Object
Class Method Details
.config_path ⇒ Object
12 13 14 |
# File 'lib/uffizzi/config_file.rb', line 12 def config_path CONFIG_PATH end |
.delete ⇒ Object
16 17 18 |
# File 'lib/uffizzi/config_file.rb', line 16 def delete File.truncate(config_path, 0) if exists? end |
.exists? ⇒ Boolean
20 21 22 |
# File 'lib/uffizzi/config_file.rb', line 20 def exists? File.exist?(config_path) end |
.list ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/uffizzi/config_file.rb', line 60 def list data = read content = data.reduce('') do |acc, pair| property, value = pair "#{acc}#{property} = #{value}\n" end Uffizzi.ui.say(content) data end |
.option_exists?(option) ⇒ Boolean
73 74 75 76 77 |
# File 'lib/uffizzi/config_file.rb', line 73 def option_exists?(option) data = read data.key?(option) end |
.option_has_value?(option) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/uffizzi/config_file.rb', line 34 def option_has_value?(option) data = read return false unless option_exists?(option) data[option].present? end |
.read_option(option, nested_option = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/uffizzi/config_file.rb', line 24 def read_option(option, nested_option = nil) data = read value = data[option] return value.presence if nested_option.nil? return nil unless value.is_a?(Hash) value[nested_option].presence end |
.rewrite_cookie(cookie) ⇒ Object
56 57 58 |
# File 'lib/uffizzi/config_file.rb', line 56 def () write_option(:cookie, ) end |
.unset_option(key) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/uffizzi/config_file.rb', line 48 def unset_option(key) data = read return unless option_exists?(key) data[key] = '' write(data) end |
.write_option(key, value) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/uffizzi/config_file.rb', line 41 def write_option(key, value) data = exists? ? read : {} data[key] = value write(data) end |