Class: Vim::Flavor::LockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vim-flavor/lockfile.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LockFile

Returns a new instance of LockFile.



10
11
12
# File 'lib/vim-flavor/lockfile.rb', line 10

def initialize(path)
  @path = path
end

Class Method Details

.load_or_new(lockfile_path) ⇒ Object



4
5
6
7
8
# File 'lib/vim-flavor/lockfile.rb', line 4

def self.load_or_new(lockfile_path)
  l = new(lockfile_path)
  l.load() if File.exists?(lockfile_path)
  l
end

.serialize_lock_status(flavor) ⇒ Object



36
37
38
# File 'lib/vim-flavor/lockfile.rb', line 36

def self.serialize_lock_status(flavor)
  ["#{flavor.repo_name} (#{flavor.locked_version})"]
end

Instance Method Details

#flavor_tableObject



14
15
16
# File 'lib/vim-flavor/lockfile.rb', line 14

def flavor_table
  @flavor_table ||= {}
end

#flavorsObject



18
19
20
# File 'lib/vim-flavor/lockfile.rb', line 18

def flavors
  flavor_table.values.sort_by {|f| f.repo_name}
end

#flavors=(fs) ⇒ Object



22
23
24
# File 'lib/vim-flavor/lockfile.rb', line 22

def flavors=(fs)
  flavor_table.replace(Hash[fs.map {|f| [f.repo_name, f]}])
end

#loadObject



26
27
28
29
30
# File 'lib/vim-flavor/lockfile.rb', line 26

def load()
  s = File.open(@path, 'r') {|io| io.read()}
  @flavor_table =
    Hash[LockFileParser.parse(s).map {|f| [f.repo_name, f]}]
end

#saveObject



40
41
42
43
44
45
46
47
48
# File 'lib/vim-flavor/lockfile.rb', line 40

def save()
  File.open(@path, 'w') do |io|
    lines = flavors.flat_map {|f| self.class.serialize_lock_status(f)}
    lines.each do |line|
      io.write(line)
      io.write("\n")
    end
  end
end

#update(completed_flavor_table) ⇒ Object



32
33
34
# File 'lib/vim-flavor/lockfile.rb', line 32

def update(completed_flavor_table)
  @flavor_table = completed_flavor_table
end