Class: Classifile::FileTools

Inherits:
Object
  • Object
show all
Defined in:
lib/classifile/io/file_tools.rb

Overview

File Utility

Class Method Summary collapse

Class Method Details

.get_file_list(path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/classifile/io/file_tools.rb', line 7

def self.get_file_list(path)
  ex_path = File.expand_path(path) # for Windows
  if !File.exist?(ex_path) # if foo/* pattern
    Dir.glob(ex_path)
  elsif File.ftype(ex_path) == "directory"
    Dir.glob(File.join(ex_path, "*")).sort
  else
    [ex_path]
  end
end

.move(src, dest, copy: false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/classifile/io/file_tools.rb', line 18

def self.move(src, dest, copy: false)
  dir = File.dirname(dest).to_s
  FileUtils.mkpath(dir)

  if copy
    FileUtils.copy(src, dest)
  else
    FileUtils.move(src, dest)
  end
end

.read_dsl(dsl_path) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/classifile/io/file_tools.rb', line 29

def self.read_dsl(dsl_path)
  begin
    f = File.open(dsl_path)
    dsl = f.read
  rescue StandardError
    p $ERROR_INFO
  ensure
    # noinspection RubyScope
    f&.close
  end
  # noinspection RubyScope
  dsl
end