Module: Norikra::Listener

Defined in:
lib/norikra/listener.rb

Defined Under Namespace

Classes: Base, Loopback, MemoryPool, Stdout

Class Method Summary collapse

Class Method Details

.listupObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/norikra/listener.rb', line 27

def self.listup
  return unless defined? Gem

  plugins = Gem.find_latest_files('norikra/listener/*.rb')
  plugins.each do |plugin|
    begin
      debug "plugin file found!", file: plugin
      rbpath = plugin.dup
      4.times do
        rbpath = File.dirname( rbpath )
      end
      files = Dir.entries( rbpath )
      gemname = files.select{|f| f=~ /\.gemspec$/ }.first.sub(/\.gemspec$/, '')
      trace "Loading listener gem", gemname: gemname, path: plugin
      require gemname
      load plugin
    rescue => e
      warn "Failed to load norikra listener plugin", plugin: plugin.to_s, error_class: e.class, error: e.message
      e.backtrace.each do |t|
        warn "  " + t
      end
    end
  end

  known_consts = [:Base, :MemoryPool, :Loopback, :Stdout]
  listeners = []
  self.constants.each do |c|
    next if known_consts.include?(c)

    klass = Norikra::Listener.const_get(c)
    if klass.is_a?(Class) && klass.superclass == Norikra::Listener::Base
      listeners.push(klass)
    end
  end
  [Norikra::Listener::Stdout, Norikra::Listener::Loopback].each do |listener|
    listeners.push(listener)
  end
  listeners
end

.parse(group_name) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/norikra/listener.rb', line 19

def self.parse(group_name)
  if group_name && group_name =~ /^([_A-Z]+)\((.*)\)$/
    {name: $1, argument: $2}
  else
    nil
  end
end