Sha256: 1f7bd5f7d385674e1b19ce6230f4518168dff6499fac1701a30e6b34d7c43919

Contents?: true

Size: 1.39 KB

Versions: 205

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8
require 'logstash/errors'
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

205 entries across 196 versions & 17 rubygems

Version Path
logstash-core-5.6.5-java lib/logstash/util/plugin_version.rb
logstash-core-6.0.0-java lib/logstash/util/plugin_version.rb
logstash-core-5.6.4-java lib/logstash/util/plugin_version.rb
logstash-core-6.0.0.rc2-java lib/logstash/util/plugin_version.rb
logstash-core-5.6.3-java lib/logstash/util/plugin_version.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/logstash-core-5.2.1-java/lib/logstash/util/plugin_version.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/logstash-core-5.2.1-java/lib/logstash/util/plugin_version.rb
logstash-core-6.0.0.rc1-java lib/logstash/util/plugin_version.rb
logstash-core-5.6.2-java lib/logstash/util/plugin_version.rb
logstash-core-5.6.1-java lib/logstash/util/plugin_version.rb
logstash-core-5.5.3-java lib/logstash/util/plugin_version.rb
logstash-core-5.6.0-java lib/logstash/util/plugin_version.rb
logstash-core-6.0.0.beta2-java lib/logstash/util/plugin_version.rb
logstash-core-5.5.2-java lib/logstash/util/plugin_version.rb
logstash-core-6.0.0.beta1-java lib/logstash/util/plugin_version.rb
logstash-core-5.5.1-java lib/logstash/util/plugin_version.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.1.snapshot1-java/lib/logstash/util/plugin_version.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.1.snapshot1-java/lib/logstash/util/plugin_version.rb
logstash-core-5.5.1.snapshot1-java lib/logstash/util/plugin_version.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.0-java/lib/logstash/util/plugin_version.rb