This class is refactored using Fluent::Registry at v0.14
# File lib/fluent/plugin.rb, line 23 def initialize @input = {} @output = {} @filter = {} @buffer = {} end
# File lib/fluent/plugin.rb, line 95 def load_plugin(type, name) try_load_plugin(name, type) end
# File lib/fluent/plugin.rb, line 85 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
# File lib/fluent/plugin.rb, line 80 def load_plugins dir = File.join(File.dirname(__FILE__), "plugin") load_plugin_dir(dir) end
# File lib/fluent/plugin.rb, line 99 def lookup_name_from_class(klass_or_str) klass = if klass_or_str.class == String eval(klass_or_str) # const_get can't handle A::B else klass_or_str end @input.each { |name, plugin| return name if plugin == klass } @output.each { |name, plugin| return name if plugin == klass } @filter.each { |name, plugin| return name if plugin == klass } nil end
# File lib/fluent/plugin.rb, line 66 def new_buffer(type) new_impl('buffer', @buffer, type) end
# File lib/fluent/plugin.rb, line 62 def new_filter(type) new_impl('filter', @filter, type) end
# File lib/fluent/plugin.rb, line 75 def new_formatter(type) require 'fluent/formatter' TextFormatter.lookup(type) end
# File lib/fluent/plugin.rb, line 54 def new_input(type) new_impl('input', @input, type) end
# File lib/fluent/plugin.rb, line 58 def new_output(type) new_impl('output', @output, type) end
# File lib/fluent/plugin.rb, line 70 def new_parser(type) require 'fluent/parser' TextParser.lookup(type) end
# File lib/fluent/plugin.rb, line 42 def register_buffer(type, klass) register_impl('buffer', @buffer, type, klass) end
# File lib/fluent/plugin.rb, line 38 def register_filter(type, klass) register_impl('filter', @filter, type, klass) end
# File lib/fluent/plugin.rb, line 50 def register_formatter(type, klass) TextFormatter.register_template(type, klass) end
# File lib/fluent/plugin.rb, line 30 def register_input(type, klass) register_impl('input', @input, type, klass) end
# File lib/fluent/plugin.rb, line 34 def register_output(type, klass) register_impl('output', @output, type, klass) end
# File lib/fluent/plugin.rb, line 46 def register_parser(type, klass) TextParser.register_template(type, klass) end
# File lib/fluent/plugin.rb, line 126 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
# File lib/fluent/plugin.rb, line 120 def register_impl(name, map, type, klass) map[type] = klass $log.trace { "registered #{name} plugin '#{type}'" } nil end
# File lib/fluent/plugin.rb, line 137 def try_load_plugin(name, type) case name when 'input' path = "fluent/plugin/in_#{type}" when 'output' path = "fluent/plugin/out_#{type}" when 'filter' path = "fluent/plugin/filter_#{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 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}" if File.exist?("#{file}.rb") require file return end } end end