Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/base/file.rb

Class Method Summary collapse

Class Method Details

.amalgamate(filename, source) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/base/file.rb', line 8

def self.amalgamate(filename, source)
  File.open(filename, "w") do |file|
    source.each do |source_file|
      file.puts IO.read(source_file)
    end
  end
end

.publish(destination, source_dir, source_glob = "**/*", exclude_glob = nil) ⇒ Object

overwrite_existing=false


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/base/file.rb', line 17

def self.publish(destination, source_dir, source_glob = "**/*", exclude_glob = nil)
  output = "\n"
  FileUtils.mkdir_p destination unless File.exist? destination

  files = nil
  Dir.chdir(source_dir) do
    files = FileList.new(source_glob).to_a
    unless exclude_glob.nil?
      FileList.new(exclude_glob).to_a.each do |f|
        files.delete(f) if files.include?(f)
      end
    end
  end
  output += "\nfiles: #{files}.to_s"

  Dir.chdir(source_dir) do
    files.each do |f|
      file = "#{destination}/#{f}"
      dirname = File.dirname(file)
      FileUtils.mkdir_p dirname unless File.exist? dirname
      FileUtils.cp(f, file) unless File.exist? file # || overwrite_existing

    end
  end
  output
end