Class: Fluent::Config::YamlParser::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/config/yaml_parser/loader.rb

Defined Under Namespace

Classes: Visitor

Constant Summary collapse

INCLUDE_TAG =
'tag:include'.freeze
FLUENT_JSON_TAG =
'tag:fluent/json'.freeze
FLUENT_STR_TAG =
'tag:fluent/s'.freeze
SHOVEL =
'<<'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(context = Kernel.binding) ⇒ Loader

Returns a new instance of Loader.



33
34
35
36
# File 'lib/fluent/config/yaml_parser/loader.rb', line 33

def initialize(context = Kernel.binding)
  @context = context
  @current_path = nil
end

Instance Method Details

#load(path) ⇒ Hash

Parameters:

  • path (String)

Returns:

  • (Hash)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluent/config/yaml_parser/loader.rb', line 40

def load(path)
  class_loader = Psych::ClassLoader.new
  scanner = Psych::ScalarScanner.new(class_loader)

  visitor = Visitor.new(scanner, class_loader)

  visitor._register_domain(INCLUDE_TAG) do |_, val|
    load(path.parent.join(val))
  end

  visitor._register_domain(FLUENT_JSON_TAG) do |_, val|
    Fluent::Config::YamlParser::FluentValue::JsonValue.new(val)
  end

  visitor._register_domain(FLUENT_STR_TAG) do |_, val|
    Fluent::Config::YamlParser::FluentValue::StringValue.new(val, @context)
  end

  path.open do |f|
    visitor.accept(Psych.parse(f))
  end
end