Class: Planter::FileList

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

Overview

File listing class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Planter.base_dir) ⇒ FileList

Initialize a new FileList object

Parameters:

  • path (String) (defaults to: Planter.base_dir)

    The base path for template



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

def initialize(path = Planter.base_dir)
  @basedir = File.realdirpath(path)

  search_path = File.join(@basedir, '**/*')
  files = Dir.glob(search_path, File::FNM_DOTMATCH).reject do |file|
    file =~ %r{/(_scripts|\.git|_config\.yml$|\.{1,2}$)}
  end

  files.sort_by!(&:length)

  @files = files.map do |file|
    new_file = "#{Planter.target}#{file.sub(/^#{@basedir}/, '').apply_variables.apply_regexes}"
    operation = Planter.overwrite ? :overwrite : :copy
    FileEntry.new(file, new_file, operation)
  end

  prepare_copy
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/planter/filelist.rb', line 6

def files
  @files
end

Instance Method Details

#copyBoolean

Public method for copying @files to target based on their operator

Returns:

  • (Boolean)

    success or failure



37
38
39
40
41
42
43
44
# File 'lib/planter/filelist.rb', line 37

def copy
  @files.each do |file|
    handle_operator(file)
  end
rescue StandardError => e
  Planter.notify("#{e}\n#{e.backtrace}", :debug, above_spinner: true)
  Planter.notify('Error copying files/directories', :error, exit_code: 128)
end