Class: Fluent::Test::ParserTestDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/test/parser_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass_or_str, format = nil, conf = {}, &block) ⇒ ParserTestDriver

Returns a new instance of ParserTestDriver.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/test/parser_test.rb', line 23

def initialize(klass_or_str, format=nil, conf={}, &block)
  if klass_or_str.is_a?(Class)
    if block
      # Create new class for test w/ overwritten methods
      #   klass.dup is worse because its ancestors does NOT include original class name
      klass_name = klass_or_str.name
      klass_or_str = Class.new(klass_or_str)
      klass_or_str.define_singleton_method("name") { klass_name }
      klass_or_str.module_eval(&block)
    end
    case klass_or_str.instance_method(:initialize).arity
    when 0
      @instance = klass_or_str.new
    when -2
      # for RegexpParser
      @instance = klass_or_str.new(format, conf)
    end
  elsif klass_or_str.is_a?(String)
    @instance = Fluent::Plugin.new_parser(klass_or_str)
  else
    @instance = klass_or_str
  end
  @config = Config.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



48
49
50
# File 'lib/fluent/test/parser_test.rb', line 48

def config
  @config
end

#instanceObject (readonly)

Returns the value of attribute instance.



48
49
50
# File 'lib/fluent/test/parser_test.rb', line 48

def instance
  @instance
end

Instance Method Details

#configure(conf) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fluent/test/parser_test.rb', line 50

def configure(conf)
  case conf
  when Fluent::Config::Element
    @config = conf
  when String
    @config = Config.parse(conf, 'fluent.conf')
  when Hash
    @config = Config::Element.new('ROOT', '', conf, [])
  else
    raise "Unknown type... #{conf}"
  end
  @instance.configure(@config)
  self
end

#parse(text, &block) ⇒ Object



65
66
67
# File 'lib/fluent/test/parser_test.rb', line 65

def parse(text, &block)
  @instance.parse(text, &block)
end