Created
February 19, 2018 16:44
-
-
Save ZephiroRB/fdfe875f6ee5a31f444c82bc7cffe314 to your computer and use it in GitHub Desktop.
Manipulate file json with Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_user_json(utoken) | |
File.read("#{path_user_json}/#{utoken}.json") | |
end | |
def delete_user_json(utoken) | |
FileUtils.rm("#{path_user_json}/#{utoken}.json") | |
end | |
def empty_user_json(utoken) | |
begin | |
FileUtils.touch("#{path_user_json}/#{utoken}.json") | |
rescue => e | |
create_user_json(utoken, {}) | |
end | |
end | |
def create_user_json(utoken, data) | |
File.open("#{path_user_json}/#{utoken}.json","w+") do |f| | |
f.write(data.to_json) | |
end | |
end | |
def path_user_json | |
Rails.root.join('public','jsons') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment