Class: Repository::FileSystem
- Inherits:
-
Object
- Object
- Repository::FileSystem
- Defined in:
- lib/repository/file_system.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
42 43 44 |
# File 'lib/repository/file_system.rb', line 42 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
64 65 66 |
# File 'lib/repository/file_system.rb', line 64 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
69 70 71 |
# File 'lib/repository/file_system.rb', line 69 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
37 38 39 |
# File 'lib/repository/file_system.rb', line 37 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
84 85 86 |
# File 'lib/repository/file_system.rb', line 84 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
47 48 49 |
# File 'lib/repository/file_system.rb', line 47 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
57 58 59 60 61 |
# File 'lib/repository/file_system.rb', line 57 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
32 33 34 |
# File 'lib/repository/file_system.rb', line 32 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
74 75 76 77 78 79 80 81 |
# File 'lib/repository/file_system.rb', line 74 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
17 18 19 |
# File 'lib/repository/file_system.rb', line 17 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
27 28 29 |
# File 'lib/repository/file_system.rb', line 27 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
22 23 24 |
# File 'lib/repository/file_system.rb', line 22 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
52 53 54 |
# File 'lib/repository/file_system.rb', line 52 def self.write(data, file_rep_path) File.open(self.sys_path(file_rep_path), WRITE) { |file| file.write(data) } end |