module GitFeats::Serializer
Public Instance Methods
serialize(path, data)
click to toggle source
serialize a ruby object to a file in json
path - file path data - data to be serialized
Returns nothing
# File lib/git-feats/serializer.rb, line 15 def serialize(path, data) # Make a path to the data file if one doesn't already exist mkpath_to path File.open(path, "w") do |f| f.puts data.to_json end end
unserialize(path)
click to toggle source
unserialize a json file to a ruby object
path - file path
Returns a ruby object or nil
# File lib/git-feats/serializer.rb, line 29 def unserialize(path) if File.exists?(path) && !File.zero?(path) begin return JSON.parse(IO.binread(path)) rescue JSON::ParserError => e puts e end end end
Private Instance Methods
mkpath_to(path)
click to toggle source
# File lib/git-feats/serializer.rb, line 41 def mkpath_to(path) unless File.exists? path FileUtils.mkpath File.dirname(path) end end