Class: Ruboto::Util::AssetCopier

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboto/util/asset_copier.rb

Instance Method Summary collapse

Constructor Details

#initialize(from, to, force = true) ⇒ AssetCopier

Returns a new instance of AssetCopier.



4
5
6
7
8
# File 'lib/ruboto/util/asset_copier.rb', line 4

def initialize(from, to, force = true)
  @from = from
  @to = to
  @force = force
end

Instance Method Details

#copy(from, to = '') ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ruboto/util/asset_copier.rb', line 10

def copy(from, to='')
  target_dir = File.join(@to, to)
  file_pattern = File.directory?(File.join(@from, from)) ? File.join(from, '**/*') : from
  existing_files = @force ? [] : Dir.chdir(target_dir){Dir[file_pattern].select{|f| !File.directory?(f)}}
  files_to_copy = Dir.chdir(@from){Dir[file_pattern].select{|f| !File.directory?(f)}} - existing_files
  files_to_copy.each do |f|
    FileUtils.mkdir_p(File.join(target_dir, File.dirname(f)))
    FileUtils.cp(File.join(@from, f), File.join(target_dir, f))
  end
end

#copy_from_absolute_path(from, to = '') ⇒ Object



21
22
23
24
# File 'lib/ruboto/util/asset_copier.rb', line 21

def copy_from_absolute_path(from, to='')
  FileUtils.mkdir_p(File.join(@to, to))
  FileUtils.cp_r(Dir[from], File.join(@to, to))
end