Sha256: f8db721a58a3b395178d50a8099ff115e07b3c6f32d11bd5a555422ad0ec0826

Contents?: true

Size: 1.36 KB

Versions: 59

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8
require 'rubygems/version'
require 'forwardable'

module LogStash::Util
  class PluginVersion
    extend Forwardable
    include Comparable

    GEM_NAME_PREFIX = 'logstash'

    def_delegators :@version, :to_s
    attr_reader :version

    def initialize(*options)
      if options.size == 1 && options.first.is_a?(Gem::Version)
        @version = options.first
      else
        @version = Gem::Version.new(options.join('.'))
      end
    end

    def self.find_version!(name)
      begin
        spec = Gem::Specification.find_by_name(name)
        if spec.nil?
          # Checking for nil? is a workaround for situations where find_by_name
          # is not able to find the real spec, as for example with pre releases
          # of plugins
          spec = Gem::Specification.find_all_by_name(name).first
        end
        new(spec.version)
      rescue Gem::LoadError
        # Rescuing the LoadError and raise a Logstash specific error.
        # Likely we can't find the gem in the current GEM_PATH
        raise LogStash::PluginNoVersionError
      end
    end

    def self.find_plugin_version!(type, name)
      plugin_name = [GEM_NAME_PREFIX, type, name].join('-')
      find_version!(plugin_name)
    end

    def <=>(other)
      version <=> other.version
    end

    private

    def self.build_from_spec(spec)
      new(spec.version)
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
logstash-core-6.8.23-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.22-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.21-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.20-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.19-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.18-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.17-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.16-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.15-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.14-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.13-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.12-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.11-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.10-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.9-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.8-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.7-java lib/logstash/util/plugin_version.rb
logstash-core-7.5.2-java lib/logstash/util/plugin_version.rb
logstash-core-7.5.1-java lib/logstash/util/plugin_version.rb
logstash-core-6.8.6-java lib/logstash/util/plugin_version.rb