Class: ConfigFile
- Inherits:
-
Object
- Object
- ConfigFile
- Defined in:
- lib/config_file.rb
Constant Summary collapse
- USER_CONFIG_DIR =
ENV.fetch('XDG_CONFIG_HOME', ENV['HOME'] + '/.config')
- SYSTEM_CONFIG_DIR =
'/etc'
- CONFIG_DIRS =
[USER_CONFIG_DIR, SYSTEM_CONFIG_DIR]
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #read ⇒ Object
Constructor Details
#initialize(filename) ⇒ ConfigFile
Returns a new instance of ConfigFile.
9 10 11 |
# File 'lib/config_file.rb', line 9 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/config_file.rb', line 7 def filename @filename end |
Class Method Details
.detect ⇒ Object
13 14 15 16 17 18 |
# File 'lib/config_file.rb', line 13 def self.detect filename = CONFIG_DIRS.map { |dir| "#{dir}/post_office/config.json" } .detect { |file| File.exist? file } new(filename) end |
Instance Method Details
#read ⇒ Object
20 21 22 23 |
# File 'lib/config_file.rb', line 20 def read return {} if @filename.nil? JSON.parse(File.read(@filename), symbolize_names: true) end |