Class: Puppet::Cleaner::ResourceTitles

Inherits:
Worker
  • Object
show all
Defined in:
lib/puppet-cleaner/workers/resourcetitles.rb

Instance Method Summary collapse

Methods inherited from Worker

#get_param

Instance Method Details

#foreach_title(line) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet-cleaner/workers/resourcetitles.rb', line 23

def foreach_title(line)
  depth = 1
  pos = line.position
  
  loop do
    pos += 1
    break if depth == 0 || pos >= line.parts.size
    case line.parts[pos].name
    when :LBRACE
      depth += 1
    when :RBRACE
      depth -= 1
    when :COLON
      next if depth != 1
      yield pos - 1
    end
  end
end

#operate(line) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet-cleaner/workers/resourcetitles.rb', line 7

def operate(line)
  pos = line.position - 1
  pos -= 1 while [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name) && pos >= 0
  return if pos < 0 || ![:NAME, :CLASS].include?(line.parts[pos].name)

  pos -= 1
  pos -= 1 while [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name) && pos >= 0
  return if [:CASE, :IF].include?(line.parts[pos].name)

  foreach_title(line) do |pos|
    if [:NAME, :CLASSREF].include?(line.parts[pos].name)
      line.parts[pos] = Part.create([:STRING, {:value => line.parts[pos].value}])
    end
  end
end

#part_namesObject



3
4
5
# File 'lib/puppet-cleaner/workers/resourcetitles.rb', line 3

def part_names
  [:LBRACE]
end