Class: LogStash::Util::PluginVersion

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/logstash/util/plugin_version.rb

Constant Summary collapse

GEM_NAME_PREFIX =
'logstash'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ PluginVersion

Returns a new instance of PluginVersion.



16
17
18
19
20
21
22
# File 'lib/logstash/util/plugin_version.rb', line 16

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

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/logstash/util/plugin_version.rb', line 14

def version
  @version
end

Class Method Details

.find_plugin_version!(type, name) ⇒ Object



41
42
43
44
# File 'lib/logstash/util/plugin_version.rb', line 41

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

.find_version!(name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/logstash/util/plugin_version.rb', line 24

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

Instance Method Details

#<=>(other) ⇒ Object



46
47
48
# File 'lib/logstash/util/plugin_version.rb', line 46

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