Class: Harmoni::JSON
- Inherits:
-
Config
show all
- Includes:
- BBLib::Effortless
- Defined in:
- lib/harmoni/types/json.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/json.rb', line 5
def self.match?(file)
if File.exist?(file)
begin
::JSON.parse(File.read(file))
true
rescue => _e
false
end
else
file.file_name =~ /\.json$/i
end
end
|
Instance Method Details
#load_config ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/harmoni/types/json.rb', line 22
def load_config
if File.exist?(path)
::JSON.parse(File.read(path))
else
{}
end
rescue => e
BBLib.logger.warn("Failed to load file as json @ #{path}: #{e}")
{}
end
|
#save ⇒ Object
18
19
20
|
# File 'lib/harmoni/types/json.rb', line 18
def save
configuration.to_json.to_file(path, mode: 'w')
end
|