File: executable.rb

package info (click to toggle)
ruby-neovim 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 548 kB
  • sloc: ruby: 4,178; sh: 23; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Neovim
  # Object representing the `nvim` executable.
  class Executable
    VERSION_PATTERN = /\ANVIM v?(.+)$/

    class Error < RuntimeError; end

    # Load the current executable from the +NVIM_EXECUTABLE+ environment
    # variable.
    #
    # @param env [Hash]
    # @return [Executable]
    def self.from_env(env=ENV)
      new(env.fetch("NVIM_EXECUTABLE", "nvim"))
    end

    attr_reader :path

    def initialize(path)
      @path = path
    end

    # Fetch the +nvim+ version.
    #
    # @return [String]
    def version
      @version ||= IO.popen([@path, "--version"]) do |io|
        io.gets[VERSION_PATTERN, 1]
      end
    rescue => e
      raise Error, "Couldn't load #{@path}: #{e}"
    end
  end
end