8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/jkeeper.rb', line 8
def self.save_json(data, fileconf={time: false, filename: nil, filepath: './', already_json: false})
time = ''
time += Time.new.strftime('%F-%H%M%S') if fileconf[:time] || fileconf[:filename].nil?
filename = time + '.json'
filename = fileconf[:filename].gsub('.json','') + time + '.json' if fileconf[:filename]
if fileconf[:filepath]
filepath = fileconf[:filepath]
else
filepath = './keep_set'
end
json = fileconf[:already_json] ? data : JSON.pretty_generate(data)
path = filepath+filename
File.write(path, json)
puts "file saved in #{File.dirname(path)}"
path
end
|