Class: Fluent::Config::DSL::Element
- Inherits:
-
BasicObject
- Defined in:
- lib/fluent/config/dsl.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, arg, proxy) ⇒ Element
Returns a new instance of Element.
79
80
81
82
83
84
85
|
# File 'lib/fluent/config/dsl.rb', line 79
def initialize(name, arg, proxy)
@name = name
@arg = arg || ''
@attrs = {}
@elements = []
@proxy = proxy
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/fluent/config/dsl.rb', line 91
def method_missing(name, *args, &block)
::Kernel.raise ::ArgumentError, "Configuration DSL Syntax Error: only one argument allowed" if args.size > 1
value = args.first
if block
proxy = Proxy.new(name.to_s, value)
proxy.element.instance_exec(&block)
@elements.push(proxy.to_config_element)
else
param_name = RESERVED_PARAMETERS.include?(name) ? "@#{name}" : name.to_s
@attrs[param_name] = if value.is_a?(Array) || value.is_a?(Hash)
JSON.dump(value)
else
value.to_s
end
end
self
end
|
Class Method Details
.const_missing(name) ⇒ Object
132
133
134
135
136
137
138
139
140
|
# File 'lib/fluent/config/dsl.rb', line 132
def self.const_missing(name)
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
if name.to_s =~ /^Fluent::Config::DSL::Element::(.*)$/
name = "#{$1}".to_sym
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
end
::Kernel.eval("#{name}")
end
|
Instance Method Details
#include(*args) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/fluent/config/dsl.rb', line 111
def include(*args)
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for include path" if args.nil? || args.size != 1
if /\.rb$/.match?(args.first)
path = File.expand_path(args.first)
data = File.read(path)
self.instance_eval(data, path)
else
ss = StringScanner.new('')
Config::V1Parser.new(ss, @proxy.include_basepath, '', nil).eval_include(@attrs, @elements, args.first)
end
end
|
#match(*args, &block) ⇒ Object
127
128
129
130
|
# File 'lib/fluent/config/dsl.rb', line 127
def match(*args, &block)
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for match pattern" if args.nil? || args.size != 1
@proxy.add_element('match', args.first, block)
end
|
#ruby(&block) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/fluent/config/dsl.rb', line 142
def ruby(&block)
if block
@proxy.instance_exec(&block)
else
::Kernel
end
end
|
#source(&block) ⇒ Object
123
124
125
|
# File 'lib/fluent/config/dsl.rb', line 123
def source(&block)
@proxy.add_element('source', nil, block)
end
|
#to_int ⇒ Object
87
88
89
|
# File 'lib/fluent/config/dsl.rb', line 87
def to_int
__id__
end
|