Class: Treetop::Runtime::SyntaxNode
- Inherits:
-
Object
- Object
- Treetop::Runtime::SyntaxNode
show all
- Defined in:
- lib/logstash/config/config_ast.rb,
lib/logstash/config/config_ast.rb
Overview
Monkeypatch Treetop::Runtime::SyntaxNode’s inspect method to skip any Whitespace or SyntaxNodes with no children.
Instance Method Summary
collapse
Instance Method Details
#_inspect(indent = "") ⇒ Object
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/logstash/config/config_ast.rb', line 355
def _inspect(indent="")
em = extension_modules
interesting_methods = methods-[em.last ? em.last.methods : nil]-self.class.instance_methods
im = interesting_methods.size > 0 ? " (#{interesting_methods.join(",")})" : ""
tv = text_value
tv = "...#{tv[-20..-1]}" if tv.size > 20
indent +
self.class.to_s.sub(/.*:/,'') +
em.map{|m| "+"+m.to_s.sub(/.*:/,'')}*"" +
" offset=#{interval.first}" +
", #{tv.inspect}" +
im +
(elements && elements.size > 0 ?
":" +
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 }||[]).map{|e|
begin
"\n"+e.inspect(indent+" ")
rescue "\n"+indent+" "+e.inspect
end
}.join("") :
""
)
end
|
#compile ⇒ Object
4
5
6
7
|
# File 'lib/logstash/config/config_ast.rb', line 4
def compile
return "" if elements.nil?
return elements.collect(&:compile).reject(&:empty?).join("")
end
|
#recursive_inject(results = [], &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/logstash/config/config_ast.rb', line 9
def recursive_inject(results=[], &block)
if !elements.nil?
elements.each do |element|
if block.call(element)
results << element
else
element.recursive_inject(results, &block)
end
end
end
return results
end
|
#recursive_inject_parent(results = [], &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/logstash/config/config_ast.rb', line 26
def recursive_inject_parent(results=[], &block)
if !parent.nil?
if block.call(parent)
results << parent
else
parent.recursive_inject_parent(results, &block)
end
end
return results
end
|
#recursive_select(klass) ⇒ Object
22
23
24
|
# File 'lib/logstash/config/config_ast.rb', line 22
def recursive_select(klass)
return recursive_inject { |e| e.is_a?(klass) }
end
|
#recursive_select_parent(results = [], klass) ⇒ Object
37
38
39
|
# File 'lib/logstash/config/config_ast.rb', line 37
def recursive_select_parent(results=[], klass)
return recursive_inject_parent(results) { |e| e.is_a?(klass) }
end
|