lib/eco/data/files/directory.rb in eco-helpers-2.0.15 vs lib/eco/data/files/directory.rb in eco-helpers-2.0.16
- old
+ new
@@ -3,25 +3,50 @@
module Eco
module Data
module Files
class Directory
+ class << self
+ def create(path, includes_file: false)
+ return true if Files.file_exists?(path)
+
+ parts = Files.split(File.expand_path(path))
+ filename = parts.pop if includes_file
+
+ return true if Files.dir_exists?(File.join(*parts))
+
+ subpath = nil
+ begin
+ parts.each do |curr|
+ subpath = subpath ? File.join(subpath, curr) : curr
+ Dir.mkdir(subpath) unless Files.dir_exists?(subpath)
+ end
+ rescue Exception => e
+ pp e
+ return false
+ end
+ true
+ end
+ end
+
attr_reader :dir_path
def initialize(dir_path = Dir.pwd)
dir_path = script_subfolder if dir_path == :script
raise "Cannot initialize with directory: '#{dir_path.to_s}'" if !dir_path || dir_path.is_a?(Symbol)
@dir_path = dir_path
end
def exists?
- Files.dir_exists(@dir_path)
+ Files.dir_exists?(@dir_path)
end
def create
- succeed = Directory.create(File.expand_path(@dir_path)) unless self.exists?
- self.full_path if succeed
+ return self.full_path if self.exists?
+ if succeed = Directory.create(File.expand_path(@dir_path))
+ return self.full_path
+ end
end
def full_path
File.expand_path(@dir_path)
end
@@ -53,26 +78,9 @@
end
def join(*args)
args.unshift(@dir_path)
File.join(*args)
- end
-
- def self.create(path, includes_file: false)
- return true if Files.file_exists?(path)
- parts = Files.split(File.expand_path(path))
- filename = parts.pop if includes_file
- return true if Files.dir_exists?(File.join(*parts))
- subpath = nil
- begin
- parts.each do |curr|
- subpath = subpath ? File.join(subpath, curr) : curr
- Dir.mkdir(subpath) unless Files.dir_exists?(subpath)
- end
- rescue Exception => e
- pp e
- end
- false
end
private
def file_pattern(value)