Module: Squared::Common::System

Defined in:
lib/squared/common/system.rb

Instance Method Summary collapse

Instance Method Details

#copy_d(src, dest, glob: ['**/*'], create: false, verbose: true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/squared/common/system.rb', line 20

def copy_d(src, dest, glob: ['**/*'], create: false, verbose: true)
  raise "#{dest} (not found)" if !create && !dest.exist?

  subdir = []
  files = 0
  dest.mkpath if create
  as_a(glob).each do |val|
    Dir.glob(src.join(val)) do |path|
      ent = Pathname.new(path)
      next if ent.directory?

      target = dest.join(ent.relative_path_from(src))
      dir = target.dirname
      if !subdir.include?(dir.to_s)
        dir.mkpath
        subdir << dir.to_s
      end
      copy_f ent, target
      files += 1
    end
  end
  puts [dest.realpath, subdir.size.to_s, files.to_s].join(' => ') if verbose
end

#copy_f(src, dest, overwrite: true, verbose: false) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/squared/common/system.rb', line 44

def copy_f(src, dest, overwrite: true, verbose: false)
  if !overwrite
    path = Pathname.new(dest)
    if path.directory?
      src = as_a(src).reject { |val| path.join(File.basename(val)).exist? }
    elsif path.exist?
      return
    end
  end
  FileUtils.cp(src, dest, verbose: verbose)
end

#shell(*cmd, **kwargs) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/squared/common/system.rb', line 8

def shell(*cmd, **kwargs)
  if /^2\.[0-5]\./.match?(RUBY_VERSION)
    exception = kwargs.delete(:exception)
    ret = system(*cmd, **kwargs)
    raise $?.to_s if !ret && exception

    ret
  else
    system(*cmd, **kwargs)
  end
end