lib/stashify/directory/local.rb in stashify-1.0.1 vs lib/stashify/directory/local.rb in stashify-1.0.2
- old
+ new
@@ -11,24 +11,32 @@
def initialize(path)
@path = path
super(name: ::File.basename(path))
end
- def write(file)
- path = ::File.join(@path, file.name)
- if file.is_a?(Stashify::Directory)
- FileUtils.mkdir(path)
- else
- ::File.write(path, file.contents)
- end
+ def write_directory(directory)
+ path = path_of(directory.name)
+ FileUtils.mkdir(path)
+ subdir = Stashify::Directory::Local.new(path)
+ directory.files.each { |file| subdir.write(file) }
end
+ def write_file(file)
+ ::File.write(path_of(file.name), file.contents)
+ end
+
def delete(name)
path = ::File.join(@path, name)
if ::File.directory?(path)
FileUtils.rm_r(path)
else
::File.delete(path)
+ end
+ end
+
+ def files
+ Dir.entries(@path).grep_v(/^[.][.]?$/).map do |file_name|
+ find(::File.basename(file_name))
end
end
def ==(other)
@path == other.path