Module: GitBak::Misc
- Defined in:
- lib/gitbak/misc.rb
Overview
miscellaneous
Defined Under Namespace
Classes: SysError
Class Method Summary collapse
-
.deepdup(obj) ⇒ Object
deep copy using Marshal.
-
.die!(msg) ⇒ Object
print msg to stderr and exit.
-
.exists?(path) ⇒ Boolean
does file/dir or symlink exists?.
-
.prompt(prompt, hide = false) ⇒ Object
prompt for line; optionally hide input.
-
.sys(cmd, *args) ⇒ Object
execute command (unless noact); optionally verbose.
-
.sys_(cmd, *args) ⇒ Object
execute command.
Class Method Details
.deepdup(obj) ⇒ Object
deep copy using Marshal
31 32 33 |
# File 'lib/gitbak/misc.rb', line 31 def self.deepdup (obj) Marshal.load(Marshal.dump obj) end |
.die!(msg) ⇒ Object
print msg to stderr and exit
36 37 38 39 |
# File 'lib/gitbak/misc.rb', line 36 def self.die! (msg) STDERR.puts msg exit 1 end |
.exists?(path) ⇒ Boolean
does file/dir or symlink exists?
42 43 44 |
# File 'lib/gitbak/misc.rb', line 42 def self.exists? (path) File.exists?(path) or File.symlink?(path) end |
.prompt(prompt, hide = false) ⇒ Object
prompt for line; optionally hide input
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gitbak/misc.rb', line 47 def self.prompt (prompt, hide = false) # {{{1 STDOUT.print prompt STDOUT.flush if hide line = STDIN.noecho { |i| i.gets } STDOUT.puts else line = STDIN.gets end line and line.chomp end |
.sys(cmd, *args) ⇒ Object
execute command (unless noact); optionally verbose
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gitbak/misc.rb', line 70 def self.sys (cmd, *args) # {{{1 opts = Hash === args.last ? args.pop : {} puts "$ #{ ([cmd] + args).join ' ' }" \ if opts[:verbose] or opts[:noact] if opts[:noact] puts '(not actually doing anything)' else sys_ cmd, *args end end |
.sys_(cmd, *args) ⇒ Object
execute command
63 64 65 66 |
# File 'lib/gitbak/misc.rb', line 63 def self.sys_ (cmd, *args) system [cmd, cmd], *args or raise SysError, "failed to run command #{ ([cmd] + args) } (#$?)" end |