Class: Warp::Dir::Serializer::Dotfile

Inherits:
Base show all
Defined in:
lib/warp/dir/serializer/dotfile.rb

Instance Attribute Summary

Attributes inherited from Base

#store

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



31
32
33
34
35
36
37
38
39
# File 'lib/warp/dir/serializer/dotfile.rb', line 31

def persist!
  File.open(warprc_file_path, 'wt') do |file|
    buffer = ''
    store.points.each do |point|
      buffer << "#{point.name}:#{point.relative_path}\n"
    end
    file.write(buffer)
  end
end

#restore!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/warp/dir/serializer/dotfile.rb', line 13

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?
      name, path = line.split(/:/)
      if name.nil? || path.nil?
        raise Warp::Dir::Errors::StoreFormatError.new("File may be corrupt - #{config.warprc}:#{line}", line)
      end
      store.add point_name: name, point_path: path
    end
  end
end

#warprc_file_pathObject



9
10
11
# File 'lib/warp/dir/serializer/dotfile.rb', line 9

def warprc_file_path
  Warp::Dir.absolute(config.warprc)
end