Class: RobotVim::InputFile

Inherits:
Object
  • Object
show all
Defined in:
lib/robot-vim/input_file.rb

Class Method Summary collapse

Class Method Details

.path_for(input, &block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/robot-vim/input_file.rb', line 3

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

.yield_existing_file_path(input, block) ⇒ Object



12
13
14
# File 'lib/robot-vim/input_file.rb', line 12

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

.yield_on_demand_file_path(input, block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/robot-vim/input_file.rb', line 16

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