module Fluent::Config
Constants
- ARRAY_TYPE
- BOOL_TYPE
- ENUM_TYPE
- FLOAT_TYPE
- HASH_TYPE
- INTEGER_TYPE
- REFORMAT_VALUE
- REGEXP_TYPE
- SIZE_TYPE
- STRING_TYPE
- TIME_TYPE
Public Class Methods
bool_value(str)
click to toggle source
# File lib/fluent/config/types.rb, line 53 def self.bool_value(str) return nil if str.nil? case str.to_s when 'true', 'yes' true when 'false', 'no' false when '' true else # Current parser passes comment without actual values, e.g. "param #foo". # parser should pass empty string in this case but changing behaviour may break existing environment so keep parser behaviour. Just ignore comment value in boolean handling for now. if str.respond_to?('start_with?') && str.start_with?('#') true else nil end end end
new(name = '')
click to toggle source
# File lib/fluent/config.rb, line 52 def self.new(name = '') Element.new(name, '', {}, []) end
parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1)
click to toggle source
# File lib/fluent/config.rb, line 23 def self.parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1) parser = if fname =~ /\.rb$/ || syntax == :ruby :ruby elsif v1_config.nil? case syntax when :v1 then :v1 when :v0 then :v0 else raise ArgumentError, "Unknown Fluentd configuration syntax: '#{syntax}'" end elsif v1_config then :v1 else :v0 end case parser when :v1 require 'fluent/config/v1_parser' V1Parser.parse(str, fname, basepath, Kernel.binding) when :v0 # TODO: show deprecated message in v1 require 'fluent/config/parser' Parser.parse(str, fname, basepath) when :ruby require 'fluent/config/dsl' Config::DSL::Parser.parse(str, File.join(basepath, fname)) else raise "[BUG] unknown configuration parser specification:'#{parser}'" end end
regexp_value(str)
click to toggle source
# File lib/fluent/config/types.rb, line 73 def self.regexp_value(str) return nil unless str return Regexp.compile(str) unless str.start_with?("/") right_slash_position = str.rindex("/") if right_slash_position < str.size - 3 raise Fluent::ConfigError, "invalid regexp: missing right slash: #{str}" end options = str[(right_slash_position + 1)..-1] option = 0 option |= Regexp::IGNORECASE if options.include?("i") option |= Regexp::MULTILINE if options.include?("m") Regexp.compile(str[1...right_slash_position], option) end
size_value(str)
click to toggle source
# File lib/fluent/config/types.rb, line 23 def self.size_value(str) case str.to_s when /([0-9]+)k/i $~[1].to_i * 1024 when /([0-9]+)m/i $~[1].to_i * (1024 ** 2) when /([0-9]+)g/i $~[1].to_i * (1024 ** 3) when /([0-9]+)t/i $~[1].to_i * (1024 ** 4) else str.to_i end end
time_value(str)
click to toggle source
# File lib/fluent/config/types.rb, line 38 def self.time_value(str) case str.to_s when /([0-9]+)s/ $~[1].to_i when /([0-9]+)m/ $~[1].to_i * 60 when /([0-9]+)h/ $~[1].to_i * 60 * 60 when /([0-9]+)d/ $~[1].to_i * 24 * 60 * 60 else str.to_f end end