aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/install_renamed.rb
blob: 02a6e9b101e56789a0fe09d1df55f6e107d388d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module InstallRenamed
  def install_p src, new_basename = nil
    super do |src, dst|
      dst += "/#{File.basename(src)}" if File.directory? dst

      if File.directory? src
        Pathname.new(dst).install Dir["#{src}/*"]
        next
      end

      append_default_if_different(src, dst)
    end
  end

  def cp_path_sub pattern, replacement
    super do |src, dst|
      append_default_if_different(src, dst)
    end
  end

  def + path
    super(path).extend(InstallRenamed)
  end

  def / path
    super(path).extend(InstallRenamed)
  end

  private

  def append_default_if_different src, dst
    if File.file? dst and !FileUtils.identical?(src, dst)
      dst += ".default"
    end
    dst
  end
end