module Fluent::Compat::CallSuperMixin

Public Class Methods

prepended(klass) click to toggle source

This mixin is to prepend to 3rd party plugins of v0.12 APIs. In past, there were not strong rule to call super in start, before_shutdown and shutdown. But v0.14 API requires to call super in these methods to setup/teardown plugin helpers and others. This mixin prepends method calls to call super forcedly if checker returns false (it shows Fluent::Plugin::Base#methods wasn't called)

# File lib/fluent/compat/call_super_mixin.rb, line 25
def self.prepended(klass)
  @@_super_start ||= {}
  @@_super_before_shutdown ||= {}
  @@_super_shutdown ||= {}

  # ancestors[0]: this module
  # ancestors[1]: prepended class (plugin itself)
  method_search = ->(ancestors, method){
    closest = ancestors[2, ancestors.size - 2].index{|m| m.method_defined?(method) }
    ancestors[2 + closest].instance_method(method)
  }
  @@_super_start[klass]           = method_search.call(klass.ancestors, :start) # this returns Fluent::Compat::*#start (or helpers on it)
  @@_super_before_shutdown[klass] = method_search.call(klass.ancestors, :before_shutdown)
  @@_super_shutdown[klass]        = method_search.call(klass.ancestors, :shutdown)
end

Public Instance Methods

before_shutdown() click to toggle source
Calls superclass method
# File lib/fluent/compat/call_super_mixin.rb, line 50
def before_shutdown
  super
  unless self.before_shutdown?
    log.warn "super was not called in #before_shutdown: calling it forcedly", plugin: self.class
    @@_super_before_shutdown[self.class].bind(self).call
  end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/compat/call_super_mixin.rb, line 67
def shutdown
  super
  unless self.shutdown?
    log.warn "super was not called in #shutdown: calling it forcedly", plugin: self.class
    @@_super_shutdown[self.class].bind(self).call
  end
end
start() click to toggle source
Calls superclass method
# File lib/fluent/compat/call_super_mixin.rb, line 41
def start
  super
  unless self.started?
    @@_super_start[self.class].bind(self).call
    # #super will reset logdev (especially in test), so this warn should be after calling it
    log.warn "super was not called in #start: called it forcedly", plugin: self.class
  end
end
stop() click to toggle source
Calls superclass method
# File lib/fluent/compat/call_super_mixin.rb, line 58
def stop
  klass = self.class
  @@_super_start.delete(klass)
  @@_super_before_shutdown.delete(klass)
  @@_super_shutdown.delete(klass)

  super
end