Class: Puppet::Pops::Model::TreeDumper
- Inherits:
-
Object
- Object
- Puppet::Pops::Model::TreeDumper
show all
- Defined in:
- lib/puppet/pops/model/tree_dumper.rb
Overview
Base class for formatted textual dump of a “model”
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(initial_indentation = 0) ⇒ TreeDumper
Returns a new instance of TreeDumper.
5
6
7
8
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 5
def initialize initial_indentation = 0
@@dump_visitor ||= Puppet::Pops::Visitor.new(nil,"dump",0,0)
@indent_count = initial_indentation
end
|
Instance Attribute Details
#indent_count ⇒ Object
4
5
6
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 4
def indent_count
@indent_count
end
|
Instance Method Details
#do_dump(o) ⇒ Object
14
15
16
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 14
def do_dump(o)
@@dump_visitor.visit_this(self, o)
end
|
10
11
12
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 10
def dump(o)
format(do_dump(o))
end
|
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 22
def format(x)
result = ""
parts = format_r(x)
parts.each_index do |i|
if i > 0
result << ' ' if parts[i] != ")" && parts[i-1] !~ /.*(?:\s+|\()$/ && parts[i] !~ /^\s+/
end
result << parts[i].to_s
end
result
end
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 35
def format_r(x)
result = []
case x
when :break
result << "\n" + indent
when :indent
@indent_count += 1
when :dedent
@indent_count -= 1
when Array
result << '('
result += x.collect {|a| format_r(a) }.flatten
result << ')'
when Symbol
result << x.to_s else
result << x
end
result
end
|
18
19
20
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 18
def indent
" " * indent_count
end
|
#is_nop?(o) ⇒ Boolean
56
57
58
|
# File 'lib/puppet/pops/model/tree_dumper.rb', line 56
def is_nop? o
o.nil? || o.is_a?(Puppet::Pops::Model::Nop)
end
|