Module: Squared::Common::System
- Defined in:
- lib/squared/common/system.rb
Class Method Summary collapse
- .copy_d(src, dest, glob: ['**/*'], pass: nil, create: false, verbose: true) ⇒ Object
- .copy_f(src, dest, overwrite: true, verbose: false) ⇒ Object
- .shell(*args, name: :system, **kwargs) ⇒ Object
Class Method Details
.copy_d(src, dest, glob: ['**/*'], pass: nil, create: false, verbose: true) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/squared/common/system.rb', line 32 def copy_d(src, dest, glob: ['**/*'], pass: nil, create: false, verbose: true) src = ::Pathname.new(src) dest = ::Pathname.new(dest) raise "#{dest} (not found)" if !create && !dest.parent.exist? subdir = [] files = 0 dest.mkpath if create if pass exclude = [] Array(pass).each { |val| exclude += ::Dir.glob(src.join(val)) } end Array(glob).each do |val| ::Dir.glob(src.join(val)) do |path| next if exclude&.include?(path) || (path = ::Pathname.new(path)).directory? target = dest.join(path.relative_path_from(src)) dir = target.dirname unless subdir.include?(dir.to_s) dir.mkpath subdir << dir.to_s end copy_f path, 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
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/squared/common/system.rb', line 61 def copy_f(src, dest, overwrite: true, verbose: false) unless overwrite if (path = ::Pathname.new(dest)).directory? src = Array(src).reject { |val| path.join(::File.basename(val)).exist? } elsif path.exist? return end end ::FileUtils.cp(src, dest, verbose: verbose) end |
.shell(*args, name: :system, **kwargs) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/squared/common/system.rb', line 11 def shell(*args, name: :system, **kwargs) if RUBY_ENGINE == 'jruby' && Rake::Win32.windows? e = kwargs[:exception] if (dir = kwargs[:chdir]) && ((pwd = Dir.pwd) != dir) Dir.chdir(dir) ret = Kernel.send(name, *args) Dir.chdir(pwd) else ret = Kernel.send(name, *args) end elsif RUBY_VERSION < '2.6' e = kwargs.delete(:exception) ret = Kernel.send(name, *args, **kwargs) else return Kernel.send(name, *args, **kwargs) end return ret if ret || !e raise $?.to_s end |