Class: Stashify::Directory::Local
Overview
An implementation for interacting with local directories. The constructor needs no information on top of what is included #initialize, although it’s important to note that setting the files parameter will not do anything.
Instance Attribute Summary
#name, #path
Instance Method Summary
collapse
#==, #delete, #delete_file, #eql?, #find, #initialize, #path_of, #write, #write_file
Instance Method Details
#delete_directory(name) ⇒ Object
46
47
48
|
# File 'lib/stashify/directory/local.rb', line 46
def delete_directory(name)
FileUtils.rm_r(path_of(name))
end
|
#directory(name) ⇒ Object
42
43
44
|
# File 'lib/stashify/directory/local.rb', line 42
def directory(name)
Stashify::Directory::Local.new(path: path_of(name))
end
|
#directory?(name) ⇒ Boolean
38
39
40
|
# File 'lib/stashify/directory/local.rb', line 38
def directory?(name)
::File.directory?(path_of(name))
end
|
#exists?(name) ⇒ Boolean
24
25
26
|
# File 'lib/stashify/directory/local.rb', line 24
def exists?(name)
::File.exist?(path_of(name))
end
|
#file(name) ⇒ Object
34
35
36
|
# File 'lib/stashify/directory/local.rb', line 34
def file(name)
Stashify::File::Local.new(path: path_of(name))
end
|
#files ⇒ Object
28
29
30
31
32
|
# File 'lib/stashify/directory/local.rb', line 28
def files
Dir.entries(path).grep_v(/^[.][.]?$/).map do |file_name|
find(file_name)
end
end
|
#parent ⇒ Object
20
21
22
|
# File 'lib/stashify/directory/local.rb', line 20
def parent
Stashify::Directory::Local.new(path: ::File.dirname(path))
end
|
#write_directory(directory) ⇒ Object
Mostly uses the default implementaiton, but needs to create the directory first so it has a valid destination.
15
16
17
18
|
# File 'lib/stashify/directory/local.rb', line 15
def write_directory(directory)
FileUtils.mkdir(path_of(directory.name))
super
end
|