class Fluent::Registry
Constants
- DEFAULT_PLUGIN_PATH
- FLUENT_LIB_PATH
Attributes
dir_search_prefix[R]
kind[R]
map[R]
paths[R]
Public Class Methods
new(kind, search_prefix, dir_search_prefix: nil)
click to toggle source
# File lib/fluent/registry.rb, line 24 def initialize(kind, search_prefix, dir_search_prefix: nil) @kind = kind @search_prefix = search_prefix @dir_search_prefix = dir_search_prefix @map = {} @paths = [] end
Public Instance Methods
lookup(type)
click to toggle source
# File lib/fluent/registry.rb, line 39 def lookup(type) type = type.to_sym if value = @map[type] return value end search(type) if value = @map[type] return value end raise ConfigError, "Unknown #{@kind} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins" # TODO error class end
register(type, value)
click to toggle source
# File lib/fluent/registry.rb, line 34 def register(type, value) type = type.to_sym @map[type] = value end
reverse_lookup(value)
click to toggle source
# File lib/fluent/registry.rb, line 51 def reverse_lookup(value) @map.each do |k, v| return k if v == value end nil end
search(type)
click to toggle source
# File lib/fluent/registry.rb, line 58 def search(type) # search from additional plugin directories if @dir_search_prefix path = "#{@dir_search_prefix}#{type}" files = @paths.map { |lp| lpath = File.expand_path(File.join(lp, "#{path}.rb")) File.exist?(lpath) ? lpath : nil }.compact unless files.empty? # prefer newer version require files.sort.last return end end path = "#{@search_prefix}#{type}" # prefer LOAD_PATH than gems files = $LOAD_PATH.map { |lp| if lp == FLUENT_LIB_PATH nil else lpath = File.expand_path(File.join(lp, "#{path}.rb")) File.exist?(lpath) ? lpath : nil end }.compact unless files.empty? # prefer newer version require files.sort.last return end # Find from gems and prefer newer version specs = Gem::Specification.find_all { |spec| if spec.name == 'fluentd'.freeze false else spec.contains_requirable_file? path end }.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 # Lastly, load built-in plugin lpath = File.expand_path(File.join(FLUENT_LIB_PATH, "#{@search_prefix}#{type}.rb")) if File.exist?(lpath) require lpath return end end