Sha256: c4969e16a670a66290f73fa58c08a10d56c29d6bbc9116023cb566bb96d29718

Contents?: true

Size: 1.14 KB

Versions: 25

Compression:

Stored size: 1.14 KB

Contents

module Prometheus
  module Client
    module Helper
      module Loader
        class << self
          def rust_impl_available?
            return @rust_available unless @rust_available.nil?

            check_for_rust
          end

          private

          def load_rust_extension
            begin
              ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
              require_relative "../../../#{ruby_version}/fast_mmaped_file_rs"
            rescue LoadError
              require 'fast_mmaped_file_rs'
            end
          end

          def check_for_rust
            # This will be evaluated on each invocation even with `||=` if
            # `@rust_available` if false. Running a `require` statement is slow,
            # so the `rust_impl_available?` method memoizes the result, external
            # callers can only trigger this method a single time.
            @rust_available = begin
              load_rust_extension
              true
            rescue LoadError
              Prometheus::Client.logger.info('FastMmapedFileRs unavailable')
              false
            end
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
prometheus-client-mmap-0.26.0 lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.26.0-x86_64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.26.0-x86_64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.26.0-arm64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.26.0-aarch64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.25.0 lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.25.0-x86_64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.25.0-x86_64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.25.0-arm64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.25.0-aarch64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.5 lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.5-x86_64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.5-x86_64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.5-arm64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.5-aarch64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.4 lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.4-x86_64-linux lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.4-x86_64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.4-arm64-darwin lib/prometheus/client/helper/loader.rb
prometheus-client-mmap-0.24.4-aarch64-linux lib/prometheus/client/helper/loader.rb