Sha256: cd697d2a9c595c322ad5b80f26c1d2dc974969758007f15795c0b2fb5a0622d9

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

module RobotVim
  class Runner
    DEFAULT_VIM_BINARY = "vim"

    def initialize(args={})
      @vim_binary = args[:vim]
    end

    def vim_binary
      @vim_binary || DEFAULT_VIM_BINARY
    end

    def run(args={})
      output_file_name = UUID.new.generate(:compact)
      commands = args[:commands] + ":w #{output_file_name}"
      commands = commands + "\n:%bd!\n:q!\n"
      invoke_vim(commands, args[:input_file])
      return File.read(output_file_name)
    ensure
      File.delete(output_file_name) if File.exists?(output_file_name)
    end

    private
    
    def invoke_vim(commands, input_file)
      ScriptFile.open(commands) do |script_file_path|
        Kernel.send(:`, "#{self.vim_binary} -n -s #{script_file_path} #{input_file}")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
robot-vim-0.9.0 lib/robot-vim/runner.rb