class R53z::JsonFile
Returns a hash of the contents of named file
Public Class Methods
fix_path_json(path)
click to toggle source
# File lib/r53z/file.rb, line 21 def self.fix_path_json(path) unless path[-5..-1] == '.json' if path[-1] == '.' return path + 'json' else return path + '.json' end end return path end
read_json(path:)
click to toggle source
# File lib/r53z/file.rb, line 10 def self.read_json(path:) file = File.read(self.fix_path_json(path)) JSON.parse(file, :symbolize_names => true) end
write_json(path:, data:)
click to toggle source
# File lib/r53z/file.rb, line 15 def self.write_json(path:, data:) File.open(self.fix_path_json(path), 'w') do |f| f.write(JSON.pretty_generate(data)) end end