Class: Lad::Files

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

Class Method Summary collapse

Class Method Details

.clone_and_orphan(url, dir) ⇒ Object



14
15
16
17
# File 'lib/files.rb', line 14

def self.clone_and_orphan(url, dir)
  Git.clone url, dir
  FileUtils.rm_rf File.join(dir, '.git')
end

.delete_temporary_files(dir) ⇒ Object



10
11
12
# File 'lib/files.rb', line 10

def self.delete_temporary_files(dir)
  FileUtils.rm_rf dir if Dir.exists? dir
end

.new_filename(item, token, name) ⇒ Object



3
4
5
6
7
8
# File 'lib/files.rb', line 3

def self.new_filename(item, token, name)
  item_dir  = File.dirname item
  item_name = File.basename(item).gsub(token, name)

  File.join item_dir, item_name
end

.replace_token_in_file(exclusions, file, token, name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/files.rb', line 19

def self.replace_token_in_file(exclusions, file, token, name)
  if exclusions.nil? || !exclusion.member?(File.extname file)
    begin
      contents = File.read(file).gsub!(token, name)
      File.open(file, 'w') { |f| 
        f.puts contents 
      }
    rescue
      # oh yeah great idea swallow exceptions! so binary files can't be parsed etc these
      # need to be excluded by the config.  Wait lets rethrow like a boss
      Console.error '  Looks like you are trying to token replace the contents of a binary. '
      Console.error '  Perhaps you need to exclude this in the .ladconfig file? '
      
      throw 'Attempting to modify binary file'
    end
  end
end