lib/stashify/directory/local.rb in stashify-1.0.4 vs lib/stashify/directory/local.rb in stashify-1.0.5

- old
+ new

@@ -4,45 +4,34 @@ require "stashify/directory" module Stashify class Directory class Local < Stashify::Directory - attr_reader :path - - def initialize(path) - @path = path - super(name: ::File.basename(path)) - end - def write_directory(directory) FileUtils.mkdir(path_of(directory.name)) super 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) + name_path = ::File.join(path, name) + if ::File.directory?(name_path) + FileUtils.rm_r(name_path) else - ::File.delete(path) + ::File.delete(name_path) end end def files - Dir.entries(@path).grep_v(/^[.][.]?$/).map do |file_name| + Dir.entries(path).grep_v(/^[.][.]?$/).map do |file_name| find(::File.basename(file_name)) end end - def ==(other) - @path == other.path - end - private def file?(name) ::File.exist?(path_of(name)) end @@ -54,14 +43,10 @@ def directory?(name) ::File.directory?(path_of(name)) end def directory(name) - Stashify::Directory::Local.new(path_of(name)) - end - - def path_of(name) - ::File.join(@path, name) + Stashify::Directory::Local.new(path: path_of(name)) end end end end