Sha256: 894ec3f8d866b91ca99ec4be82f9c7869b63a1e4605e4ca44d2eab93b3ba4550

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

require 'vim_recovery'

module VimRecovery
  class Command
    def initialize(paths, options = {})
      @paths = paths
      @options = options
    end

    def patterns
      @patterns ||=
        if @options[:recursive]
          SWAPFILES.map { |swp| "**/#{swp}" }
        else
          SWAPFILES
        end
    end

    def each_swapfile &block
      @paths.each do |path|
        path = path.chomp '/'
        path_patterns = patterns.map { |swp| "#{path}/#{swp}" }

        Dir.glob(path_patterns, File::FNM_DOTMATCH).each do |filename|
          next unless File.file? filename

          begin
            swapfile = VimRecovery::Swapfile.open filename
            next unless swapfile.valid_block0?
            yield swapfile
          ensure
            swapfile.close
          end
        end
      end
    end
  end
end

require_relative 'command/list'
require_relative 'command/clean'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vim-recovery-0.0.1 lib/vim_recovery/command.rb