Module: Squared::Common::System
- Defined in:
- lib/squared/common/system.rb
Class Method Summary collapse
- .copy_d(src, dest, glob: ['**/*'], create: false, verbose: true) ⇒ Object
- .copy_f(src, dest, overwrite: true, verbose: false) ⇒ Object
- .shell(*args, **kwargs) ⇒ Object
Class Method Details
.copy_d(src, dest, glob: ['**/*'], create: false, verbose: true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/squared/common/system.rb', line 23 def copy_d(src, dest, glob: ['**/*'], create: false, verbose: true) src = Pathname.new(src) dest = Pathname.new(dest) raise "#{dest} (not found)" if !create && !dest.exist? subdir = [] files = 0 dest.mkpath if create (glob.is_a?(::Array) ? glob : [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 unless 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(Common::ARG[:SPACE]) if verbose end |
.copy_f(src, dest, overwrite: true, verbose: false) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/squared/common/system.rb', line 49 def copy_f(src, dest, overwrite: true, verbose: false) unless overwrite if (path = Pathname.new(dest)).directory? src = [src] unless src.is_a?(::Array) src = src.reject { |val| path.join(File.basename(val)).exist? } elsif path.exist? return end end FileUtils.cp(src, dest, verbose: verbose) end |
.shell(*args, **kwargs) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/squared/common/system.rb', line 11 def shell(*args, **kwargs) if RUBY_VERSION =~ /^2\.[0-5]\./ exception = kwargs.delete(:exception) ret = system(*args, **kwargs) raise $?.to_s if !ret && exception ret else system(*args, **kwargs) end end |