class Fluent::PluginClass
Public Class Methods
new()
click to toggle source
This class is refactored using Fluent::Registry at v0.14
# File lib/fluent/plugin.rb, line 22 def initialize @input = {} @output = {} @buffer = {} end
Public Instance Methods
load_plugin(type, name)
click to toggle source
# File lib/fluent/plugin.rb, line 83 def load_plugin(type, name) try_load_plugin(name, type) end
load_plugin_dir(dir)
click to toggle source
# File lib/fluent/plugin.rb, line 73 def load_plugin_dir(dir) dir = File.expand_path(dir) Dir.entries(dir).sort.each {|fname| if fname =~ /\.rb$/ require File.join(dir, fname) end } nil end
load_plugins()
click to toggle source
# File lib/fluent/plugin.rb, line 68 def load_plugins dir = File.join(File.dirname(__FILE__), "plugin") load_plugin_dir(dir) end
new_buffer(type)
click to toggle source
# File lib/fluent/plugin.rb, line 56 def new_buffer(type) new_impl('buffer', @buffer, type) end
new_formatter(type)
click to toggle source
# File lib/fluent/plugin.rb, line 64 def new_formatter(type) TextFormatter.lookup(type) end
new_input(type)
click to toggle source
# File lib/fluent/plugin.rb, line 48 def new_input(type) new_impl('input', @input, type) end
new_output(type)
click to toggle source
# File lib/fluent/plugin.rb, line 52 def new_output(type) new_impl('output', @output, type) end
new_parser(type)
click to toggle source
# File lib/fluent/plugin.rb, line 60 def new_parser(type) TextParser.lookup(type) end
register_buffer(type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 36 def register_buffer(type, klass) register_impl('buffer', @buffer, type, klass) end
register_formatter(type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 44 def register_formatter(type, klass) TextFormatter.register_template(type, klass) end
register_input(type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 28 def register_input(type, klass) register_impl('input', @input, type, klass) end
register_output(type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 32 def register_output(type, klass) register_impl('output', @output, type, klass) end
register_parser(type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 40 def register_parser(type, klass) TextParser.register_template(type, klass) end
Private Instance Methods
new_impl(name, map, type)
click to toggle source
# File lib/fluent/plugin.rb, line 94 def new_impl(name, map, type) if klass = map[type] return klass.new end try_load_plugin(name, type) if klass = map[type] return klass.new end raise ConfigError, "Unknown #{name} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins" end
register_impl(name, map, type, klass)
click to toggle source
# File lib/fluent/plugin.rb, line 88 def register_impl(name, map, type, klass) map[type] = klass $log.trace { "registered #{name} plugin '#{type}'" } nil end
try_load_plugin(name, type)
click to toggle source
# File lib/fluent/plugin.rb, line 105 def try_load_plugin(name, type) case name when 'input' path = "fluent/plugin/in_#{type}" when 'output' path = "fluent/plugin/out_#{type}" when 'buffer' path = "fluent/plugin/buf_#{type}" else return end # prefer LOAD_PATH than gems files = $LOAD_PATH.map {|lp| lpath = File.join(lp, "#{path}.rb") File.exist?(lpath) ? lpath : nil }.compact unless files.empty? # prefer newer version require File.expand_path(files.sort.last) return end # search gems if defined?(::Gem::Specification) && ::Gem::Specification.respond_to?(:find_all) specs = Gem::Specification.find_all {|spec| spec.contains_requirable_file? path } # prefer newer version specs = specs.sort_by {|spec| spec.version } if spec = specs.last spec.require_paths.each {|lib| file = "#{spec.full_gem_path}/#{lib}/#{path}" require file } end # backward compatibility for rubygems < 1.8 elsif defined?(::Gem) && ::Gem.respond_to?(:searcher) #files = Gem.find_files(path).sort specs = Gem.searcher.find_all(path) # prefer newer version specs = specs.sort_by {|spec| spec.version } specs.reverse_each {|spec| files = Gem.searcher.matching_files(spec, path) unless files.empty? require files.first break end } end end