Class: Repository::FileSystem
- Inherits:
-
Object
- Object
- Repository::FileSystem
- Defined in:
- lib/repository/file_system/base.rb,
lib/repository/file_system/helpers.rb
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- ROOT_DEFAULT =
you should override ROOT appropriately, depending on where you want your repo located
'/'
- WRITE =
"w"
- READ =
"r"
Class Method Summary collapse
-
.chmod(rep_path, permission) ⇒ Object
Change the permission of a file.
-
.cp(from_rep_path, to_rep_path) ⇒ Object
Copy the file from param1 to location specified in param2.
-
.cpdir(from_rep_path, to_rep_path) ⇒ Object
Same as cp except recrusive.
-
.delete(rep_path) ⇒ Object
Delete a file at the given path in the repository.
-
.directory_contents(rep_path, filter = '*') ⇒ Object
Return the filtered contents of a directory in an array.
-
.exists?(rep_path) ⇒ Boolean
Return whether a path exists or not.
-
.mkdir(rep_dir, permission = 0777) ⇒ Object
Create the specified directory and any parent dirs in the root.
-
.read(rep_path) ⇒ Object
Read the file data specified by the given path.
-
.rmdir(rep_dir) ⇒ Object
Delete the specified directory and contents in the root.
-
.root_array ⇒ Object
Return the array of the repository root.
-
.sys_path(rep_path = []) ⇒ Object
Return the full file system path of the given directory or file.
-
.sys_path_array(rep_path = []) ⇒ Object
Return the full file system path of the given directory or file.
-
.write(data, file_rep_path) ⇒ Object
Writes file data to the given path.
Class Method Details
.chmod(rep_path, permission) ⇒ Object
Change the permission of a file
38 39 40 |
# File 'lib/repository/file_system/base.rb', line 38 def self.chmod(rep_path, ) File.chmod(, self.sys_path(rep_path)) end |
.cp(from_rep_path, to_rep_path) ⇒ Object
Copy the file from param1 to location specified in param2
60 61 62 |
# File 'lib/repository/file_system/base.rb', line 60 def self.cp(from_rep_path, to_rep_path) FileUtils.cp(self.sys_path(from_rep_path), self.sys_path(to_rep_path)) end |
.cpdir(from_rep_path, to_rep_path) ⇒ Object
Same as cp except recrusive
65 66 67 |
# File 'lib/repository/file_system/base.rb', line 65 def self.cpdir(from_rep_path, to_rep_path) FileUtils.cp_r(self.sys_path(from_rep_path), self.sys_path(to_rep_path)) end |
.delete(rep_path) ⇒ Object
Delete a file at the given path in the repository
33 34 35 |
# File 'lib/repository/file_system/base.rb', line 33 def self.delete(rep_path) File.delete(self.sys_path(rep_path)) if self.exists?(rep_path) end |
.directory_contents(rep_path, filter = '*') ⇒ Object
Return the filtered contents of a directory in an array
80 81 82 |
# File 'lib/repository/file_system/base.rb', line 80 def self.directory_contents(rep_path, filter = '*') Dir[self.sys_path(rep_path+[filter])] end |
.exists?(rep_path) ⇒ Boolean
Return whether a path exists or not
43 44 45 |
# File 'lib/repository/file_system/base.rb', line 43 def self.exists?(rep_path) File.exists?(self.sys_path(rep_path)) end |
.mkdir(rep_dir, permission = 0777) ⇒ Object
Create the specified directory and any parent dirs in the root
53 54 55 56 57 |
# File 'lib/repository/file_system/base.rb', line 53 def self.mkdir(rep_dir, =0777) FileUtils.makedirs(self.sys_path(rep_dir)) FileUtils.chmod(, self.sys_path(rep_dir)) rep_dir end |
.read(rep_path) ⇒ Object
Read the file data specified by the given path
28 29 30 |
# File 'lib/repository/file_system/base.rb', line 28 def self.read(rep_path) File.open(self.sys_path(rep_path), READ) { |file| yield file.read } end |
.rmdir(rep_dir) ⇒ Object
Delete the specified directory and contents in the root
70 71 72 73 74 75 76 77 |
# File 'lib/repository/file_system/base.rb', line 70 def self.rmdir(rep_dir) sys_path = self.sys_path(rep_dir) if File.exists?(sys_path) Dir.foreach(sys_path) {|file_name| File.delete(self.sys_path(rep_dir+[file_name])) if !File.directory?(self.sys_path(rep_dir+[file_name])) } Dir.delete(sys_path) end rep_dir end |
.root_array ⇒ Object
Return the array of the repository root
13 14 15 |
# File 'lib/repository/file_system/base.rb', line 13 def self.root_array (ROOT || ROOT_DEFAULT).split(File::SEPARATOR) end |
.sys_path(rep_path = []) ⇒ Object
Return the full file system path of the given directory or file
23 24 25 |
# File 'lib/repository/file_system/base.rb', line 23 def self.sys_path(rep_path = []) sys_path_array(rep_path).join(File::SEPARATOR) end |
.sys_path_array(rep_path = []) ⇒ Object
Return the full file system path of the given directory or file
18 19 20 |
# File 'lib/repository/file_system/base.rb', line 18 def self.sys_path_array(rep_path = []) self.root_array+rep_path end |
.write(data, file_rep_path) ⇒ Object
Writes file data to the given path
48 49 50 |
# File 'lib/repository/file_system/base.rb', line 48 def self.write(data, file_rep_path) File.open(self.sys_path(file_rep_path), WRITE) { |file| file.write(data) } end |