lib/stashify/directory/local.rb in stashify-1.0 vs lib/stashify/directory/local.rb in stashify-1.0.1
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require "stashify/file"
+require "stashify/file/local"
require "stashify/directory"
module Stashify
class Directory
class Local < Stashify::Directory
@@ -11,20 +11,10 @@
def initialize(path)
@path = path
super(name: ::File.basename(path))
end
- def find(name)
- path = ::File.join(@path, name)
- if ::File.directory?(path)
- Stashify::Directory::Local.new(path)
- else
- file = ::File.read(path)
- Stashify::File.new(name: name, contents: file)
- end
- end
-
def write(file)
path = ::File.join(@path, file.name)
if file.is_a?(Stashify::Directory)
FileUtils.mkdir(path)
else
@@ -41,9 +31,27 @@
end
end
def ==(other)
@path == other.path
+ end
+
+ private
+
+ def directory?(name)
+ ::File.directory?(path_of(name))
+ end
+
+ def file(name)
+ Stashify::File::Local.new(path_of(name))
+ end
+
+ def directory(name)
+ Stashify::Directory::Local.new(path_of(name))
+ end
+
+ def path_of(name)
+ ::File.join(@path, name)
end
end
end
end