Class: Link

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/clenver/link.rb

Constant Summary collapse

MAX_REPEAT =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(src, dst) ⇒ Link

Returns a new instance of Link.



8
9
10
11
# File 'lib/clenver/link.rb', line 8

def initialize(src,dst)
  @src = src
  @dst = dst
end

Instance Attribute Details

#dstObject

Returns the value of attribute dst.



7
8
9
# File 'lib/clenver/link.rb', line 7

def dst
  @dst
end

#srcObject

Returns the value of attribute src.



7
8
9
# File 'lib/clenver/link.rb', line 7

def src
  @src
end

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/clenver/link.rb', line 13

def create
  puts "Link.create"
  dst.each do |d|
    i = 0
    d = d.to_s.gsub(/\$\w+/) {|m| ENV[m[1..-1]]}
    logger.debug("d:#{d}")
    logger.debug("src:#{src.gsub(/\$\w+/) {|n| ENV[n[1..-1]]}}")
    while i < MAX_REPEAT do
      begin
        File.symlink(src.gsub(/\$\w+/) {|n| ENV[n[1..-1]]}, d)
      rescue SystemCallError
        FileUtils.mv(d, d + "_old")
      else
        logge.debug("else")
        break
      end
      i += 1
    end
  end
end