Sha256: 2624e3fa32b0a7197c4948132c4d021a543c29e342c309c42d5c297982ee2a47

Contents?: true

Size: 570 Bytes

Versions: 5

Compression:

Stored size: 570 Bytes

Contents

module RobotVim
  class InputFile
    def self.path_for(input, &block)
      if File.exists?(input)
        yield_existing_file_path(input, block)
      else
        yield_on_demand_file_path(input, block)
      end
    end


    def self.yield_existing_file_path(input, block)
      block.call(input)
    end

    def self.yield_on_demand_file_path(input, block)
      file_name = FileNameGenerator.generate
      File.open(file_name, "w+") do |file|
        file << input
      end
      block.call(file_name)
    ensure
      File.delete(file_name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
robot-vim-2.0.1 lib/robot-vim/input_file.rb
robot-vim-2.0.0 lib/robot-vim/input_file.rb
robot-vim-1.1.0 lib/robot-vim/input_file.rb
robot-vim-1.0.0 lib/robot-vim/input_file.rb
robot-vim-0.10.0 lib/robot-vim/input_file.rb