Class: Warp::Dir::Serializer::Dotfile
- Defined in:
- lib/warp/dir/serializer/dotfile.rb
Overview
Serializer only assumes that Points can serialize themselves or deserialize themselves to/from a one-line text format.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#config, inherited, #initialize
Constructor Details
This class inherits a constructor from Warp::Dir::Serializer::Base
Instance Method Details
#persist! ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/warp/dir/serializer/dotfile.rb', line 30 def persist! File.open(warprc_file_path, 'wt') do |file| buffer = '' store.points.each do |point| buffer << "#{point.serialize}\n" end file.write(buffer) end end |
#restore! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/warp/dir/serializer/dotfile.rb', line 15 def restore! unless File.exist?(warprc_file_path) $stderr.puts "No warprc file found in the path #{warprc_file_path}" if config.debug return end File.open(warprc_file_path, 'r') do |f| f.each_line do |line| line = line.chomp next if line.blank? line.gsub!(/["']/,'') # remove any quotes that may have been inserted store.add(point: Warp::Dir::Point.deserialize(line)) end end end |