buzzcore 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/buzzcore.gemspec +3 -2
- data/lib/buzzcore/misc_utils.rb +42 -8
- data/test/misc_test.rb +42 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/buzzcore.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{buzzcore}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["buzzware"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-16}
|
13
13
|
s.description = %q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
|
14
14
|
s.email = %q{contact@buzzware.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -59,6 +59,7 @@ Gem::Specification.new do |s|
|
|
59
59
|
"test/buzzcore_test.rb",
|
60
60
|
"test/config_test.rb",
|
61
61
|
"test/credentials_test.rb",
|
62
|
+
"test/misc_test.rb",
|
62
63
|
"test/shell_test.rb",
|
63
64
|
"test/test_helper.rb"
|
64
65
|
]
|
data/lib/buzzcore/misc_utils.rb
CHANGED
@@ -163,8 +163,42 @@ module MiscUtils
|
|
163
163
|
return aPath if !aBasePath
|
164
164
|
return path_relative?(aPath) ? File.join(aBasePath,aPath) : aPath
|
165
165
|
end
|
166
|
+
|
167
|
+
# make path real according to file system
|
168
|
+
def self.real_path(aPath)
|
169
|
+
(path = Pathname.new(File.expand_path(aPath))) && path.realpath
|
170
|
+
end
|
171
|
+
|
172
|
+
# takes a path and combines it with a root path (which defaults to Dir.pwd) unless it is absolute
|
173
|
+
# the final result is then expanded
|
174
|
+
def self.canonize_path(aPath,aRootPath=nil)
|
175
|
+
path = path_combine(aRootPath,aPath)
|
176
|
+
path = real_path(path) if path
|
177
|
+
path
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.find_upwards(aStartPath,aPath)
|
181
|
+
curr_path = File.expand_path(aStartPath)
|
182
|
+
while curr_path && !(test_path_exists = File.exists?(test_path = File.join(curr_path,aPath))) do
|
183
|
+
curr_path = MiscUtils.path_parent(curr_path)
|
184
|
+
end
|
185
|
+
curr_path && test_path_exists ? test_path : nil
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
# allows special symbols in path
|
190
|
+
# currently only ... supported, which looks upward in the filesystem for the following relative path from the basepath
|
191
|
+
def self.expand_magic_path(aPath,aBasePath=nil)
|
192
|
+
aBasePath ||= Dir.pwd
|
193
|
+
path = aPath
|
194
|
+
if path.begins_with?('...')
|
195
|
+
rel_part = StringUtils.split3(path,/\.\.\.[\/\\]/)[2]
|
196
|
+
path = find_upwards(aBasePath,rel_part)
|
197
|
+
end
|
198
|
+
end
|
166
199
|
|
167
200
|
def self.path_parent(aPath)
|
201
|
+
return nil if is_root_path?(aPath)
|
168
202
|
MiscUtils.append_slash(File.dirname(MiscUtils.remove_slash(File.expand_path(aPath))))
|
169
203
|
end
|
170
204
|
|
@@ -214,6 +248,14 @@ module MiscUtils
|
|
214
248
|
/^[a-zA-Z0-9+_]+\:\/\// =~ aString ? true : false
|
215
249
|
end
|
216
250
|
|
251
|
+
def self.is_root_path?(aPath)
|
252
|
+
if is_windows?
|
253
|
+
(aPath =~ /^[a-zA-Z]\:[\\\/]$/)==0
|
254
|
+
else
|
255
|
+
aPath == '/'
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
217
259
|
def self.native_path(aPath)
|
218
260
|
is_windows? ? windows_path(aPath) : ruby_path(aPath)
|
219
261
|
end
|
@@ -231,14 +273,6 @@ module MiscUtils
|
|
231
273
|
def self.is_windows?
|
232
274
|
platform=='mswin32'
|
233
275
|
end
|
234
|
-
|
235
|
-
# takes a path and combines it with a root path (which defaults to Dir.pwd) unless it is absolute
|
236
|
-
# the final result is then expanded
|
237
|
-
def self.canonize_path(aPath,aRootPath=nil)
|
238
|
-
path = Pathname.new(aPath)
|
239
|
-
path = Pathname.new(aRootPath || Dir.pwd)+path if path.relative?
|
240
|
-
File.expand_path(path)
|
241
|
-
end
|
242
276
|
|
243
277
|
def self.get_files(aArray,aPath,aFullPath=true,aRootPath=nil,&block)
|
244
278
|
#puts "get_files: aPath='#{aPath}'"
|
data/test/misc_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
gem 'Shoulda'; require 'shoulda'
|
10
|
+
|
11
|
+
require 'fileutils'
|
12
|
+
|
13
|
+
gem 'buzzcore'; require 'buzzcore'
|
14
|
+
|
15
|
+
class MiscTest < Test::Unit::TestCase
|
16
|
+
|
17
|
+
context "expand_magic_path" do
|
18
|
+
|
19
|
+
setup do
|
20
|
+
@temp_path = MiscUtils.canonize_path(MiscUtils.make_temp_dir('expand_magic_path'))
|
21
|
+
FileUtils.mkdir_p(@c = File.join(@temp_path,'a/b/c'))
|
22
|
+
FileUtils.mkdir_p(@aaa = File.join(@temp_path,'aaa'))
|
23
|
+
@xxx = MiscUtils.make_temp_file('xxx',@aaa)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "expand leading .../ and find existing path" do
|
27
|
+
assert_equal @aaa,MiscUtils.expand_magic_path('.../aaa',@c)
|
28
|
+
assert_equal @xxx,MiscUtils.expand_magic_path('.../aaa/xxx',@c)
|
29
|
+
Dir.chdir(@c) do
|
30
|
+
assert_equal @aaa,MiscUtils.expand_magic_path('.../aaa')
|
31
|
+
assert_equal @xxx,MiscUtils.expand_magic_path('.../aaa/xxx')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return nil when expand leading .../ fails" do
|
36
|
+
assert_equal nil,MiscUtils.expand_magic_path('.../aaa/xyz',@c)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buzzcore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzzware
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-16 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -105,5 +105,6 @@ test_files:
|
|
105
105
|
- test/buzzcore_test.rb
|
106
106
|
- test/config_test.rb
|
107
107
|
- test/credentials_test.rb
|
108
|
+
- test/misc_test.rb
|
108
109
|
- test/shell_test.rb
|
109
110
|
- test/test_helper.rb
|