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.



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

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.



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

def version
  @version
end

Class Method Details

.find_plugin_version!(type, name) ⇒ Object



34
35
36
37
# File 'lib/logstash/util/plugin_version.rb', line 34

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

.find_version!(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/logstash/util/plugin_version.rb', line 23

def self.find_version!(name)
  begin
    specification = Gem::Specification.find_by_name(name)
    new(specification.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



39
40
41
# File 'lib/logstash/util/plugin_version.rb', line 39

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