Class: FPM::Cookery::Path
- Inherits:
-
Pathname
- Object
- Pathname
- FPM::Cookery::Path
- Defined in:
- lib/fpm/cookery/path.rb
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #/(path) ⇒ Object
- #install(src, new_basename = nil) ⇒ Object
-
#install_p(src, new_basename = nil) ⇒ Object
deprecated
Deprecated.
Will be made private in the future.
- #mkdir ⇒ Object
Class Method Details
.pwd(path = nil) ⇒ Object
11 12 13 |
# File 'lib/fpm/cookery/path.rb', line 11 def self.pwd(path = nil) new(Dir.pwd)/path end |
Instance Method Details
#+(other) ⇒ Object
15 16 17 18 |
# File 'lib/fpm/cookery/path.rb', line 15 def +(other) other = Path.new(other) unless Path === other Path.new(plus(@path, other.to_s)) end |
#/(path) ⇒ Object
20 21 22 |
# File 'lib/fpm/cookery/path.rb', line 20 def /(path) self + (path || '').gsub(%r{^/}, '') end |
#install(src, new_basename = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fpm/cookery/path.rb', line 28 def install(src, new_basename = nil) case src when Array src.collect {|src| install_p(src) } when Hash src.collect {|src, new_basename| install_p(src, new_basename) } else install_p(src, new_basename) end end |
#install_p(src, new_basename = nil) ⇒ Object
Deprecated.
Will be made private in the future.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fpm/cookery/path.rb', line 41 def install_p(src, new_basename = nil) if new_basename new_basename = File.basename(new_basename) # rationale: see Pathname.+ dst = self/new_basename return_value = Path.new(dst) else dst = self return_value = self/File.basename(src) end src = src.to_s dst = dst.to_s # if it's a symlink, don't resolve it to a file because if we are moving # files one by one, it's likely we will break the symlink by moving what # it points to before we move it # and also broken symlinks are not the end of the world raise "#{src} does not exist" unless File.symlink? src or File.exist? src mkpath FileUtils.cp_r src, dst, :preserve => true # if File.symlink? src # # we use the BSD mv command because FileUtils copies the target and # # not the link! I'm beginning to wish I'd used Python quite honestly! # raise unless Kernel.system 'mv', src, dst # else # # we mv when possible as it is faster and you should only be using # # this function when installing from the temporary build directory # FileUtils.mv src, dst # end return return_value end |
#mkdir ⇒ Object
24 25 26 |
# File 'lib/fpm/cookery/path.rb', line 24 def mkdir FileUtils.mkdir_p(self.to_s) end |