Sha256: d99e4a8efa1cc56622ee19592526a6cd4ff4443689c71a7ff185016063c55a32

Contents?: true

Size: 1.12 KB

Versions: 13

Compression:

Stored size: 1.12 KB

Contents

module Vim
  module Flavor
    class LockFile
      def self.load_or_new(lockfile_path)
        l = new(lockfile_path)
        l.load() if File.exists?(lockfile_path)
        l
      end

      def initialize(path)
        @path = path
      end

      def flavor_table
        @flavor_table ||= {}
      end

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

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

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

      def update(completed_flavor_table)
        @flavor_table = completed_flavor_table
      end

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

      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vim-flavor-2.2.2 lib/vim-flavor/lockfile.rb
vim-flavor-2.2.1 lib/vim-flavor/lockfile.rb
vim-flavor-2.2.0 lib/vim-flavor/lockfile.rb
vim-flavor-2.1.1 lib/vim-flavor/lockfile.rb
vim-flavor-2.1.0 lib/vim-flavor/lockfile.rb
vim-flavor-2.0.0 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.5 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.4 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.3 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.2 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.1 lib/vim-flavor/lockfile.rb
vim-flavor-1.1.0 lib/vim-flavor/lockfile.rb
vim-flavor-1.0.3 lib/vim-flavor/lockfile.rb