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.7.1-java lib/logstash/util/plugin_version.rb
logstash-core-7.0.0.rc2-java lib/logstash/util/plugin_version.rb
logstash-core-7.0.0.rc1-java lib/logstash/util/plugin_version.rb
logstash-core-6.7.0-java lib/logstash/util/plugin_version.rb
logstash-core-6.6.2-java lib/logstash/util/plugin_version.rb
logstash-core-6.6.1-java lib/logstash/util/plugin_version.rb
logstash-core-7.0.0.beta1-java lib/logstash/util/plugin_version.rb
logstash-core-6.6.0-java lib/logstash/util/plugin_version.rb
logstash-core-7.0.0.alpha2-java lib/logstash/util/plugin_version.rb
logstash-core-6.5.4-java lib/logstash/util/plugin_version.rb
logstash-core-6.5.3-java lib/logstash/util/plugin_version.rb
logstash-core-6.5.2-java lib/logstash/util/plugin_version.rb
logstash-core-6.5.1-java lib/logstash/util/plugin_version.rb
logstash-core-7.0.0.alpha1-java lib/logstash/util/plugin_version.rb
logstash-core-6.5.0-java lib/logstash/util/plugin_version.rb
logstash-core-6.4.3-java lib/logstash/util/plugin_version.rb
logstash-core-6.4.2-java lib/logstash/util/plugin_version.rb
logstash-core-6.4.1-java lib/logstash/util/plugin_version.rb
logstash-core-6.4.0-java lib/logstash/util/plugin_version.rb