Class: Harmoni::YAML
- Inherits:
-
Config
show all
- Includes:
- BBLib::Effortless
- Defined in:
- lib/harmoni/types/yaml.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Config
#clear, #delete, #delete!, detect_type, #get, #get_all, #reload, #set, #sync, #watching?
Class Method Details
.match?(file) ⇒ Boolean
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/harmoni/types/yaml.rb', line 5
def self.match?(file)
if File.exist?(file)
begin
::YAML.load_file(file)
true
rescue => _e
false
end
else
file.file_name =~ /\.(yml|yaml)$/i
end
end
|
Instance Method Details
#load_config ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/harmoni/types/yaml.rb', line 22
def load_config
if File.exist?(path)
::YAML.load_file(path)
else
{}
end
rescue => e
BBLib.logger.warn("Failed to load file as yaml @ #{path}: #{e}")
{}
end
|
#save ⇒ Object
18
19
20
|
# File 'lib/harmoni/types/yaml.rb', line 18
def save
configuration.to_h.to_yaml.to_file(path, mode: 'w')
end
|