kelredd-repository 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/repository/file_system.rb +90 -3
- data/lib/repository/version.rb +1 -1
- data/lib/repository.rb +0 -1
- metadata +2 -3
- data/lib/repository/file_system/base.rb +0 -86
data/README.rdoc
CHANGED
@@ -24,12 +24,12 @@ Check out the code for more detail.
|
|
24
24
|
Repository::FileSystem::ROOT = "/some/path/to/a/repo"
|
25
25
|
|
26
26
|
|
27
|
-
(mixes in all kinds of helper methods for dealing with files and paths at above root)
|
28
27
|
include FileSystem
|
28
|
+
(mixes in all kinds of helper methods for dealing with files and paths at above root)
|
29
29
|
|
30
30
|
== License
|
31
31
|
|
32
|
-
Copyright (c)
|
32
|
+
Copyright (c) 2009 Kelly Redding
|
33
33
|
|
34
34
|
Permission is hereby granted, free of charge, to any person
|
35
35
|
obtaining a copy of this software and associated documentation
|
@@ -1,3 +1,90 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
1
|
+
Dir[File.join(File.dirname(__FILE__), "file_system" ,"*.rb")].each do |file|
|
2
|
+
require file
|
3
|
+
end
|
4
|
+
|
5
|
+
module Repository
|
6
|
+
class FileSystem
|
7
|
+
|
8
|
+
# all path designations should be passed as arrays, where each array element corresponds to a path segment
|
9
|
+
# the class handles joining the segments with the appropriate seperator
|
10
|
+
|
11
|
+
# you should override ROOT appropriately, depending on where you want your repo located
|
12
|
+
ROOT_DEFAULT = '/'
|
13
|
+
WRITE = "w"
|
14
|
+
READ = "r"
|
15
|
+
|
16
|
+
# Return the array of the repository root
|
17
|
+
def self.root_array
|
18
|
+
(ROOT || ROOT_DEFAULT).split(File::SEPARATOR)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return the full file system path of the given directory or file
|
22
|
+
def self.sys_path_array(rep_path = [])
|
23
|
+
self.root_array+rep_path
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return the full file system path of the given directory or file
|
27
|
+
def self.sys_path(rep_path = [])
|
28
|
+
sys_path_array(rep_path).join(File::SEPARATOR)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Read the file data specified by the given path
|
32
|
+
def self.read(rep_path)
|
33
|
+
File.open(self.sys_path(rep_path), READ) { |file| yield file.read }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Delete a file at the given path in the repository
|
37
|
+
def self.delete(rep_path)
|
38
|
+
File.delete(self.sys_path(rep_path)) if self.exists?(rep_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Change the permission of a file
|
42
|
+
def self.chmod(rep_path, permission)
|
43
|
+
File.chmod(permission, self.sys_path(rep_path))
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return whether a path exists or not
|
47
|
+
def self.exists?(rep_path)
|
48
|
+
File.exists?(self.sys_path(rep_path))
|
49
|
+
end
|
50
|
+
|
51
|
+
# Writes file data to the given path
|
52
|
+
def self.write(data, file_rep_path)
|
53
|
+
File.open(self.sys_path(file_rep_path), WRITE) { |file| file.write(data) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Create the specified directory and any parent dirs in the root
|
57
|
+
def self.mkdir(rep_dir, permission=0777)
|
58
|
+
FileUtils.makedirs(self.sys_path(rep_dir))
|
59
|
+
FileUtils.chmod(permission, self.sys_path(rep_dir))
|
60
|
+
rep_dir
|
61
|
+
end
|
62
|
+
|
63
|
+
# Copy the file from param1 to location specified in param2
|
64
|
+
def self.cp(from_rep_path, to_rep_path)
|
65
|
+
FileUtils.cp(self.sys_path(from_rep_path), self.sys_path(to_rep_path))
|
66
|
+
end
|
67
|
+
|
68
|
+
# Same as cp except recrusive
|
69
|
+
def self.cpdir(from_rep_path, to_rep_path)
|
70
|
+
FileUtils.cp_r(self.sys_path(from_rep_path), self.sys_path(to_rep_path))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Delete the specified directory and contents in the root
|
74
|
+
def self.rmdir(rep_dir)
|
75
|
+
sys_path = self.sys_path(rep_dir)
|
76
|
+
if File.exists?(sys_path)
|
77
|
+
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])) }
|
78
|
+
Dir.delete(sys_path)
|
79
|
+
end
|
80
|
+
rep_dir
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return the filtered contents of a directory in an array
|
84
|
+
def self.directory_contents(rep_path, filter = '*')
|
85
|
+
Dir[self.sys_path(rep_path+[filter])]
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/lib/repository/version.rb
CHANGED
data/lib/repository.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelredd-repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelredd
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,7 +26,6 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- lib/repository
|
28
28
|
- lib/repository/file_system
|
29
|
-
- lib/repository/file_system/base.rb
|
30
29
|
- lib/repository/file_system/helpers.rb
|
31
30
|
- lib/repository/file_system.rb
|
32
31
|
- lib/repository/version.rb
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module Repository
|
2
|
-
class FileSystem
|
3
|
-
|
4
|
-
# all path designations should be passed as arrays, where each array element corresponds to a path segment
|
5
|
-
# the class handles joining the segments with the appropriate seperator
|
6
|
-
|
7
|
-
# you should override ROOT appropriately, depending on where you want your repo located
|
8
|
-
ROOT_DEFAULT = '/'
|
9
|
-
WRITE = "w"
|
10
|
-
READ = "r"
|
11
|
-
|
12
|
-
# Return the array of the repository root
|
13
|
-
def self.root_array
|
14
|
-
(ROOT || ROOT_DEFAULT).split(File::SEPARATOR)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Return the full file system path of the given directory or file
|
18
|
-
def self.sys_path_array(rep_path = [])
|
19
|
-
self.root_array+rep_path
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return the full file system path of the given directory or file
|
23
|
-
def self.sys_path(rep_path = [])
|
24
|
-
sys_path_array(rep_path).join(File::SEPARATOR)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Read the file data specified by the given path
|
28
|
-
def self.read(rep_path)
|
29
|
-
File.open(self.sys_path(rep_path), READ) { |file| yield file.read }
|
30
|
-
end
|
31
|
-
|
32
|
-
# Delete a file at the given path in the repository
|
33
|
-
def self.delete(rep_path)
|
34
|
-
File.delete(self.sys_path(rep_path)) if self.exists?(rep_path)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Change the permission of a file
|
38
|
-
def self.chmod(rep_path, permission)
|
39
|
-
File.chmod(permission, self.sys_path(rep_path))
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return whether a path exists or not
|
43
|
-
def self.exists?(rep_path)
|
44
|
-
File.exists?(self.sys_path(rep_path))
|
45
|
-
end
|
46
|
-
|
47
|
-
# Writes file data to the given path
|
48
|
-
def self.write(data, file_rep_path)
|
49
|
-
File.open(self.sys_path(file_rep_path), WRITE) { |file| file.write(data) }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Create the specified directory and any parent dirs in the root
|
53
|
-
def self.mkdir(rep_dir, permission=0777)
|
54
|
-
FileUtils.makedirs(self.sys_path(rep_dir))
|
55
|
-
FileUtils.chmod(permission, self.sys_path(rep_dir))
|
56
|
-
rep_dir
|
57
|
-
end
|
58
|
-
|
59
|
-
# Copy the file from param1 to location specified in param2
|
60
|
-
def self.cp(from_rep_path, to_rep_path)
|
61
|
-
FileUtils.cp(self.sys_path(from_rep_path), self.sys_path(to_rep_path))
|
62
|
-
end
|
63
|
-
|
64
|
-
# Same as cp except recrusive
|
65
|
-
def self.cpdir(from_rep_path, to_rep_path)
|
66
|
-
FileUtils.cp_r(self.sys_path(from_rep_path), self.sys_path(to_rep_path))
|
67
|
-
end
|
68
|
-
|
69
|
-
# Delete the specified directory and contents in the root
|
70
|
-
def self.rmdir(rep_dir)
|
71
|
-
sys_path = self.sys_path(rep_dir)
|
72
|
-
if File.exists?(sys_path)
|
73
|
-
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])) }
|
74
|
-
Dir.delete(sys_path)
|
75
|
-
end
|
76
|
-
rep_dir
|
77
|
-
end
|
78
|
-
|
79
|
-
# Return the filtered contents of a directory in an array
|
80
|
-
def self.directory_contents(rep_path, filter = '*')
|
81
|
-
Dir[self.sys_path(rep_path+[filter])]
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|