lib/refinements/pathnames.rb in refinements-7.12.0 vs lib/refinements/pathnames.rb in refinements-7.13.0
- old
+ new
@@ -11,12 +11,13 @@
super
end
end
refine Pathname do
- def name
- basename extname
+ def change_dir &block
+ Dir.chdir(self, &block)
+ self
end
def copy to
destination = to.directory? ? to.join(basename) : to
read.then { |content| destination.write content }
@@ -37,29 +38,49 @@
def gsub pattern, replacement
self.class.new to_s.gsub(pattern, replacement)
end
+ def make_ancestors
+ dirname.mkpath
+ self
+ end
+
+ def make_dir
+ exist? ? self : mkdir and self
+ end
+
+ def make_path
+ mkpath
+ self
+ end
+
+ def mkdir
+ exist? ? self : super and self
+ end
+
+ def name
+ basename extname
+ end
+
def relative_parent root_dir
relative_path_from(root_dir).parent
end
def relative_parent_from root_dir
warn "[DEPRECATION]: Pathname#relative_parent_from is deprecated, " \
"use Pathname#relative_parent instead."
relative_parent root_dir
end
- def make_ancestors
- dirname.mkpath
- self
+ def remove_dir
+ exist? ? (rmdir and self) : self
end
- # rubocop:disable Style/RedundantSelf
- def mkdir
- self.exist? ? self : super and self
+ def remove_tree
+ rmtree if exist?
+ self
end
- # rubocop:enable Style/RedundantSelf
def rewrite
read.then { |content| write yield(content) if block_given? }
self
end