Class: Puppet::Cleaner::Symlink

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

Instance Method Summary collapse

Methods inherited from Worker

#get_param

Instance Method Details

#foreach_colon(line) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet-cleaner/workers/symlink.rb', line 30

def foreach_colon(line)
  pos = line.position
  pos += 1 while pos < line.parts.size && line.parts[pos].name != :LBRACE
  depth = 1
  
  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
    end
  end
end

#operate(line) ⇒ Object



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

#part_namesObject



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

def part_names
  [:NAME]
end