Class: Simmer::Externals::LocalFileSystem

Inherits:
FileSystem
  • Object
show all
Defined in:
lib/simmer/externals/local_file_system.rb

Overview

Provides the implementation for using a local directory

Instance Method Summary collapse

Constructor Details

#initialize(root, files_dir) ⇒ LocalFileSystem

Returns a new instance of LocalFileSystem.



16
17
18
19
20
21
22
23
24
# File 'lib/simmer/externals/local_file_system.rb', line 16

def initialize(root, files_dir)
  root = File.expand_path(root.to_s)

  super(root)

  @files_dir = files_dir.to_s

  freeze
end

Instance Method Details

#clean!Object



36
37
38
39
40
41
42
# File 'lib/simmer/externals/local_file_system.rb', line 36

def clean!
  glob      = File.join(root, '**', '*')
  all_files = Dir[glob].reject { |p| File.directory?(p) }

  all_files.each { |path| FileUtils.rm(path) }
  all_files.length
end

#write!(input_files) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/simmer/externals/local_file_system.rb', line 26

def write!(input_files)
  input_files.each do |input_file|
    src = File.join(files_dir, input_file.src)

    write_single(input_file.dest, src)
  end

  input_files.length
end