7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/puppet-cleaner/workers/symlink.rb', line 7
def operate(line)
return if line.current.value != 'file'
pos = line.position + 1
pos += 1 while pos < line.parts.size && [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name)
return if pos >= line.parts.size || line.parts[pos].name != :LBRACE
foreach_colon(line) {|colonpos|
start, endpos = get_param(line, 'ensure', colonpos)
next if start.nil?
pos = start + 1
pos += 1 while pos < line.parts.size && line.parts[pos].name != :FARROW
pos += 1
pos += 1 while pos < line.parts.size && [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name)
value = line.parts[pos].value
next if [:NAME, :STRING].include?(line.parts[pos].name) && %w(present absent file directory link symlink).include?(value)
next if line.parts[pos].name == :VARIABLE
ensure_param = [ [:RETURN, {:value => "\n"}], [:NAME, {:value => "ensure"}], [:FARROW, {:value => '=>'}], [:NAME, {:value => 'link'}], [:COMMA, {:value => ","}] ].map {|e| Part.create(e) }
start += 1 while line.parts[start].name != :NAME
line.parts[start].value = 'target'
line.append(colonpos, ensure_param)
}
end
|