File: version.rb

package info (click to toggle)
ruby-rjb 1.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 704 kB
  • sloc: ansic: 3,859; ruby: 2,604; java: 247; makefile: 35; sh: 3
file content (27 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (2)
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
module Rjb
  class << self

    private

    # @return [String, nil] the valid version number. Can be nil.
    def read_version
      path = File.expand_path('../../../ext/rjb.c', __FILE__)
      File.open(path) do |f|
        f.each_line do |l|
          m = /RJB_VERSION\s+"(.+?)"/.match(l)

          # The file is closed even in this case.
          return m[1] if m
        end
      end
    end
  end

  # The `Rjb` module defines `VERSION` in the C code.
  # If Rjb is already required we have the constant.
  unless defined?(::Rjb::VERSION)
    unless (VERSION = read_version)
      raise 'Cannot find a valid version number in `rjb.c`!'
    end
  end
end