Class: VimRecovery::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vim_recovery/command.rb

Direct Known Subclasses

Clean, List

Defined Under Namespace

Classes: Clean, List

Instance Method Summary collapse

Constructor Details

#initialize(paths, options = {}) ⇒ Command

Returns a new instance of Command.



5
6
7
8
# File 'lib/vim_recovery/command.rb', line 5

def initialize(paths, options = {})
  @paths = paths
  @options = options
end

Instance Method Details

#each_swapfile(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vim_recovery/command.rb', line 19

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

#patternsObject



10
11
12
13
14
15
16
17
# File 'lib/vim_recovery/command.rb', line 10

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