torquebox-vfs 1.0.0.CR1-java → 1.0.0.CR2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,11 +52,71 @@ class Dir
52
52
  result
53
53
  end
54
54
 
55
- def [](pattern)
55
+ def [](*pattern)
56
56
  self.glob( pattern )
57
57
  end
58
58
 
59
- def glob(pattern,flags=0, &block)
59
+ def glob(pattern, flags=0, &block)
60
+ patterns = [pattern].flatten
61
+ patterns.collect { |pattern| glob_one( pattern, flags, &block ) }.flatten
62
+ end
63
+
64
+ def chdir(*args, &block)
65
+ raise "You shouldn't use chdir, but if you must, pass a block!" unless block_given?
66
+ chdir_before_vfs( *args.map{ |x| File.name_without_vfs(x) }, &block )
67
+ end
68
+
69
+ def rmdir(path)
70
+ name = File.name_without_vfs(path)
71
+ rmdir_before_vfs(name)
72
+ end
73
+ alias_method :unlink, :rmdir
74
+ alias_method :delete, :rmdir
75
+
76
+ def mkdir(path, mode=0777)
77
+ mkdir_before_vfs( File.name_without_vfs(path), mode )
78
+ rescue Errno::ENOTDIR => e
79
+ path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
80
+ mkdir_before_vfs( path, mode )
81
+ rescue Errno::ENOENT => e
82
+ path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
83
+ mkdir_before_vfs( path, mode )
84
+ end
85
+
86
+ # 1.8: new( dirname )
87
+ # 1.9: new( dirname, <, :encoding => enc> )
88
+ # We currently ignore the encoding.
89
+ def new(string, options = nil)
90
+ if ( ::File.exist_without_vfs?( string ) )
91
+ return new_before_vfs( string )
92
+ end
93
+ TorqueBox::VFS::Dir.new( string )
94
+ end
95
+
96
+ # 1.9 has an optional, undocumented options arg that appears to be
97
+ # used for encoding. We'll ignore it for now, since JRuby does as
98
+ # well. (see org.jruby.RubyDir.java)
99
+ def entries(path, options = {})
100
+ if ( ::File.exist_without_vfs?( path ) )
101
+ return entries_before_vfs(path)
102
+ end
103
+ vfs_dir = org.jboss.vfs::VFS.child( File.path_to_str(path) )
104
+ # Delegate to original entries if passed a nonexistent file
105
+ unless vfs_dir.exists?
106
+ return entries_before_vfs( path )
107
+ end
108
+ [ '.', '..' ] + vfs_dir.children.collect{|e| e.name }
109
+ end
110
+
111
+ def foreach(path, &block)
112
+ enum = entries(path).each(&block)
113
+ block_given? ? nil : enum
114
+ end
115
+
116
+ private
117
+
118
+ def glob_one(pattern, flags=0, &block)
119
+
60
120
  is_absolute_vfs = false
61
121
 
62
122
  #str_pattern = "#{pattern}"
@@ -131,58 +191,6 @@ class Dir
131
191
  end
132
192
  end
133
193
 
134
- def chdir(*args, &block)
135
- raise "You shouldn't use chdir, but if you must, pass a block!" unless block_given?
136
- chdir_before_vfs( *args.map{ |x| File.name_without_vfs(x) }, &block )
137
- end
138
-
139
- def rmdir(path)
140
- name = File.name_without_vfs(path)
141
- rmdir_before_vfs(name)
142
- end
143
- alias_method :unlink, :rmdir
144
- alias_method :delete, :rmdir
145
-
146
- def mkdir(path, mode=0777)
147
- mkdir_before_vfs( File.name_without_vfs(path), mode )
148
- rescue Errno::ENOTDIR => e
149
- path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
150
- mkdir_before_vfs( path, mode )
151
- rescue Errno::ENOENT => e
152
- path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
153
- mkdir_before_vfs( path, mode )
154
- end
155
-
156
- # 1.8: new( dirname )
157
- # 1.9: new( dirname, <, :encoding => enc> )
158
- # We currently ignore the encoding.
159
- def new(string, options = nil)
160
- if ( ::File.exist_without_vfs?( string ) )
161
- return new_before_vfs( string )
162
- end
163
- TorqueBox::VFS::Dir.new( string )
164
- end
165
-
166
- # 1.9 has an optional, undocumented options arg that appears to be
167
- # used for encoding. We'll ignore it for now, since JRuby does as
168
- # well. (see org.jruby.RubyDir.java)
169
- def entries(path, options = {})
170
- if ( ::File.exist_without_vfs?( path ) )
171
- return entries_before_vfs(path)
172
- end
173
- vfs_dir = org.jboss.vfs::VFS.child( File.path_to_str(path) )
174
- # Delegate to original entries if passed a nonexistent file
175
- unless vfs_dir.exists?
176
- return entries_before_vfs( path )
177
- end
178
- [ '.', '..' ] + vfs_dir.children.collect{|e| e.name }
179
- end
180
-
181
- def foreach(path, &block)
182
- enum = entries(path).each(&block)
183
- block_given? ? nil : enum
184
- end
185
-
186
194
  end
187
195
  end
188
196
 
Binary file
data/lib/torquebox-vfs.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module TorqueboxVfs
2
- VERSION = '1.0.0.CR1'
3
- MAVEN_VERSION = '1.0.0.CR1'
2
+ VERSION = '1.0.0.CR2'
3
+ MAVEN_VERSION = '1.0.0.CR2'
4
4
  end
5
5
  begin
6
6
  require 'java'
data/spec/dir_spec.rb CHANGED
@@ -206,6 +206,35 @@ describe "Dir extensions for VFS" do
206
206
  items.should_not include( "#{prefix}/home/larry/archive1.jar/lib/archive4.txt" )
207
207
  end
208
208
 
209
+ it "should allow globbing of an array of patterns" do
210
+ items = []
211
+ lambda {
212
+ items = Dir.glob( ["#{prefix}/home/larry/*", "#{prefix}/home/todd/*"] )
213
+ }.should_not raise_error
214
+
215
+ items.should include( "#{prefix}/home/larry/file1.txt" )
216
+ items.should include( "#{prefix}/home/todd/index.html.haml" )
217
+ end
218
+
219
+ it "should allow globbing of multiple patterns via []" do
220
+ items = []
221
+ lambda {
222
+ items = Dir["#{prefix}/home/larry/*", "#{prefix}/home/todd/*"]
223
+ }.should_not raise_error
224
+
225
+ items.should include( "#{prefix}/home/larry/file1.txt" )
226
+ items.should include( "#{prefix}/home/todd/index.html.haml" )
227
+ end
228
+
229
+ it "should allow globbing of a single pattern via []" do
230
+ items = []
231
+ lambda {
232
+ items = Dir["#{prefix}/home/larry/*"]
233
+ }.should_not raise_error
234
+
235
+ items.should include( "#{prefix}/home/larry/file1.txt" )
236
+ end
237
+
209
238
  it "should create new Dirs" do
210
239
  lambda {
211
240
  Dir.new(prefix)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-vfs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.CR1
5
+ version: 1.0.0.CR2
6
6
  platform: java
7
7
  authors: []
8
8
 
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 -04:00
13
+ date: 2011-04-25 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency