fspath 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTE3MTE5ZGQzNTAyZGRiMjUxNTI1M2E4MDMzZGVjM2I3OGUyMDAyOQ==
4
+ ZWMyZGJiOTM2MzZkOWQwZTljNjE4Yjc3MmI5MTAxOTliNDU0OTdmZA==
5
5
  data.tar.gz: !binary |-
6
- ZGU1YmZmMDhkMWRmYjQzNDExN2RhNjI3OWIxZjc5NWU2MmFlYTQyZg==
6
+ ZWFkODdkNTRlOTQyYjFmZDVkYjZhM2JjM2VmZTQ2NWZjZGViMzliYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzdiYzcyNTZlNTc1ZTEwMjYxMDY4MWM5ZDNhMzdlNWQ4N2I0Y2I1NTNhY2I5
10
- ODE1YjU5NzNlODVhNzFmYTc3YjkxMGZkOGU4MjMwMTUyYzIwYjE2ODg5ZjFk
11
- ZTkwNWE5YmM4MTRjOWVjMzI3Y2I0ODcyNzRiNjRiMWZkNGJlNDA=
9
+ ZGVhNmZhYTZjODQzNWYzMzA0OGNkOGRjNjhmNmQyNWYzNDQyMWU3ZThjNDE5
10
+ MmJmYzc5NTI0NGFlYTE5ZjgxMzE1N2Y2ZDhjOTJiYmJjZjUxNzc4ODA1ZWFi
11
+ ZGJmN2U4ZjEwM2ExYTk0ZGFhMzJhOWVjYmEyZDZkYjRhMjc2YTU=
12
12
  data.tar.gz: !binary |-
13
- ODQ3ZmU3NWQzYjcyZjQ2ZWFiNDUzZjFlZTE3OWEwN2QwZjFhYTI2OTliOGYy
14
- MTZiZDA3NDhkZDJkNjY0NTkzNWVmZTg0YzA4ZTQwZGQzMzUxYzFiM2U5MGQw
15
- ODBjNGY2ODRhN2ZlZjA4MmQ0MDlkOWRkZDMyZTk3ZjYzMTA5YzA=
13
+ ZWU5Yjc2OGViYjkwMDNhNzE4MDNiMjUwZjkzZmY5NTFhYjFkYWQ2Y2RkNGRm
14
+ MjM5ODE3ODE3ZmI4OGVhZjc1MzI0NmFlNGE1YTdmM2Q0ZWRkNzc2ODg0ZTM3
15
+ OTI2Y2Q4ZTgyMDRhOTcxOTJkY2E0YzkwOWE1Y2UyZTYwNzBmZmU=
@@ -6,7 +6,5 @@ rvm:
6
6
  - 2.0.0
7
7
  - jruby-18mode
8
8
  - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
11
9
  - ree
12
10
  script: "bundle exec rspec"
@@ -42,10 +42,12 @@ Expand glob:
42
42
 
43
43
  Ascendants:
44
44
 
45
+ FSPath('a/b/c').ascendants
45
46
  FSPath('a/b/c').ascend # => [FSPath('a/b/c'), FSPath('a/b'), FSPath('a')]
46
47
 
47
48
  Descendants:
48
49
 
50
+ FSPath('a/b/c').descendants
49
51
  FSPath('a/b/c').descend # => [FSPath('a'), FSPath('a/b'), FSPath('a/b/c')]
50
52
 
51
53
  Path parts:
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'fspath'
5
- s.version = '2.0.6'
5
+ s.version = '2.1.0'
6
6
  s.summary = %q{Better than Pathname}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -39,7 +39,7 @@ class FSPath < Pathname
39
39
  # Returns common dir for paths
40
40
  def common_dir(*paths)
41
41
  paths.map do |path|
42
- new(path).dirname.ascend
42
+ new(path).ascendants.drop(1)
43
43
  end.inject(:&).first
44
44
  end
45
45
 
@@ -83,9 +83,9 @@ class FSPath < Pathname
83
83
  end
84
84
 
85
85
  unless (new('a') + 'b').is_a?(self)
86
- # Fixing Pathname.+
86
+ # Fixing Pathname#+
87
87
  def +(other)
88
- self.class.new(plus(@path, other.to_s))
88
+ self.class.new(super)
89
89
  end
90
90
  end
91
91
 
@@ -121,36 +121,130 @@ class FSPath < Pathname
121
121
  self.class.glob(*args, &block)
122
122
  end
123
123
 
124
- # Iterates over and yields each element in the given path in ascending order
125
- def ascend(&block)
126
- ascendants = []
124
+ # Returns list of elements in the given path in ascending order
125
+ def ascendants
126
+ paths = []
127
127
  path = @path
128
- ascendants << self
128
+ paths << self
129
129
  while r = chop_basename(path)
130
130
  path, name = r
131
131
  break if path.empty?
132
- ascendants << self.class.new(del_trailing_separator(path))
133
- end
134
- if block
135
- ascendants.each(&block)
132
+ paths << self.class.new(del_trailing_separator(path))
136
133
  end
137
- ascendants
134
+ paths
135
+ end
136
+
137
+ # Returns list of elements in the given path in descending order
138
+ def descendants
139
+ ascendants.reverse
140
+ end
141
+
142
+ # Iterates over and yields each element in the given path in ascending order
143
+ def ascend(&block)
144
+ paths = ascendants
145
+ paths.each(&block) if block
146
+ paths
138
147
  end
139
148
 
140
149
  # Iterates over and yields each element in the given path in descending order
141
150
  def descend(&block)
142
- descendants = ascend.reverse
143
- if block
144
- descendants.each(&block)
145
- end
146
- descendants
151
+ paths = descendants
152
+ paths.each(&block) if block
153
+ paths
147
154
  end
148
155
 
149
156
  # Returns path parts
150
- def parts(&block)
157
+ def parts
151
158
  split_names(@path).flatten
152
159
  end
153
160
 
161
+ unless new('a').basename.is_a?(self)
162
+ # Fixing glob
163
+ def self.glob(*args)
164
+ if block_given?
165
+ super{ |f| yield new(f) }
166
+ else
167
+ super.map{ |f| new(f) }
168
+ end
169
+ end
170
+
171
+ # Fixing getwd
172
+ def self.getwd
173
+ new(super)
174
+ end
175
+
176
+ # Fixing pwd
177
+ def self.pwd
178
+ new(super)
179
+ end
180
+
181
+ # Fixing basename
182
+ def basename(*args)
183
+ self.class.new(super)
184
+ end
185
+
186
+ # Fixing dirname
187
+ def dirname
188
+ self.class.new(super)
189
+ end
190
+
191
+ # Fixing expand_path
192
+ def expand_path(*args)
193
+ self.class.new(super)
194
+ end
195
+
196
+ # Fixing split
197
+ def split
198
+ super.map{ |f| self.class.new(f) }
199
+ end
200
+
201
+ # Fixing sub
202
+ def sub(pattern, *rest, &block)
203
+ self.class.new(super)
204
+ end
205
+
206
+ if Pathname.method_defined?(:sub_ext)
207
+ # Fixing sub_ext
208
+ def sub_ext(ext)
209
+ self.class.new(super)
210
+ end
211
+ end
212
+
213
+ # Fixing realpath
214
+ def realpath
215
+ self.class.new(super)
216
+ end
217
+
218
+ if Pathname.method_defined?(:realdirpath)
219
+ # Fixing realdirpath
220
+ def realdirpath
221
+ self.class.new(super)
222
+ end
223
+ end
224
+
225
+ # Fixing readlink
226
+ def readlink
227
+ self.class.new(super)
228
+ end
229
+
230
+ # Fixing each_entry
231
+ def each_entry
232
+ super{ |f| yield self.class.new(f) }
233
+ end
234
+
235
+ # Fixing entries
236
+ def entries
237
+ super.map{ |f| self.class.new(f) }
238
+ end
239
+ end
240
+
241
+ unless new('a').inspect.include?('FSPath')
242
+ # Fixing inspect
243
+ def inspect
244
+ "#<#{self.class}:#{@path}>"
245
+ end
246
+ end
247
+
154
248
  private
155
249
 
156
250
  def escape_glob_string
@@ -208,41 +208,57 @@ describe FSPath do
208
208
  end
209
209
 
210
210
  describe "path parts" do
211
- describe "ascend" do
211
+ describe "ascending" do
212
212
  before do
213
213
  @path = FSPath('/a/b/c')
214
214
  @ascendants = %w[/a/b/c /a/b /a /].map(&method(:FSPath))
215
215
  end
216
216
 
217
- it "should return list of ascendants" do
218
- @path.ascend.should == @ascendants
217
+ describe "ascendants" do
218
+ it "should return list of ascendants" do
219
+ @path.ascendants.should == @ascendants
220
+ end
219
221
  end
220
222
 
221
- it "should yield and return list of ascendants if called with block" do
222
- ascendants = []
223
- @path.ascend do |path|
224
- ascendants << path
225
- end.should == @ascendants
226
- ascendants.should == @ascendants
223
+ describe "ascend" do
224
+ it "should return list of ascendants" do
225
+ @path.ascend.should == @ascendants
226
+ end
227
+
228
+ it "should yield and return list of ascendants if called with block" do
229
+ ascendants = []
230
+ @path.ascend do |path|
231
+ ascendants << path
232
+ end.should == @ascendants
233
+ ascendants.should == @ascendants
234
+ end
227
235
  end
228
236
  end
229
237
 
230
- describe "descend" do
238
+ describe "descending" do
231
239
  before do
232
240
  @path = FSPath('/a/b/c')
233
241
  @descendants = %w[/ /a /a/b /a/b/c].map(&method(:FSPath))
234
242
  end
235
243
 
236
- it "should return list of descendants" do
237
- @path.descend.should == @descendants
244
+ describe "descendants" do
245
+ it "should return list of descendants" do
246
+ @path.descendants.should == @descendants
247
+ end
238
248
  end
239
249
 
240
- it "should yield and return list of descendants if called with block" do
241
- descendants = []
242
- @path.descend do |path|
243
- descendants << path
244
- end.should == @descendants
245
- descendants.should == @descendants
250
+ describe "descend" do
251
+ it "should return list of descendants" do
252
+ @path.descend.should == @descendants
253
+ end
254
+
255
+ it "should yield and return list of descendants if called with block" do
256
+ descendants = []
257
+ @path.descend do |path|
258
+ descendants << path
259
+ end.should == @descendants
260
+ descendants.should == @descendants
261
+ end
246
262
  end
247
263
  end
248
264
 
@@ -252,4 +268,128 @@ describe FSPath do
252
268
  end
253
269
  end
254
270
  end
271
+
272
+ describe "returning/yield instances of FSPath" do
273
+ def fspath?(path)
274
+ path.should be_instance_of(FSPath)
275
+ end
276
+
277
+ def fspaths?(paths)
278
+ paths.each do |path|
279
+ fspath? path
280
+ end
281
+ end
282
+
283
+ it "should for glob" do
284
+ fspaths? FSPath(__FILE__).glob
285
+
286
+ FSPath(__FILE__).glob do |path|
287
+ fspath? path
288
+ end
289
+ end
290
+
291
+ it "should for pwd" do
292
+ fspath? FSPath.pwd
293
+ end
294
+
295
+ it "should for getwd" do
296
+ fspath? FSPath.getwd
297
+ end
298
+
299
+ it "should for basename" do
300
+ fspath? FSPath('a/b').basename
301
+ end
302
+
303
+ it "should for dirname" do
304
+ fspath? FSPath('a/b').dirname
305
+ end
306
+
307
+ it "should for parent" do
308
+ fspath? FSPath('a/b').parent
309
+ end
310
+
311
+ it "should for cleanpath" do
312
+ fspath? FSPath('a/b').cleanpath
313
+ end
314
+
315
+ it "should for expand_path" do
316
+ fspath? FSPath('a/b').expand_path
317
+ end
318
+
319
+ it "should for relative_path_from" do
320
+ fspath? FSPath('a').relative_path_from('b')
321
+ end
322
+
323
+ it "should for join" do
324
+ fspath? FSPath('a').join('b', 'c')
325
+ end
326
+
327
+ it "should for split" do
328
+ fspaths? FSPath('a/b').split
329
+ end
330
+
331
+ it "should for sub" do
332
+ fspath? FSPath('a/b').sub('a', 'c')
333
+ fspath? FSPath('a/b').sub('a'){ 'c' }
334
+ end
335
+
336
+ it "should for sub_ext" do
337
+ fspath? FSPath('a/b').sub_ext('.rb')
338
+ end if FSPath.method_defined?(:sub_ext)
339
+
340
+ it "should for readlink" do
341
+ FSPath.temp_dir do |dir|
342
+ symlink = dir + 'sym'
343
+ symlink.make_symlink __FILE__
344
+ fspath? symlink.readlink
345
+ end
346
+ end
347
+
348
+ it "should for realdirpath" do
349
+ fspath? FSPath(__FILE__).realdirpath
350
+ end if FSPath.method_defined?(:realdirpath)
351
+
352
+ it "should for realpath" do
353
+ fspath? FSPath(__FILE__).realpath
354
+ end
355
+
356
+ it "should for children" do
357
+ fspaths? FSPath('.').children
358
+ end
359
+
360
+ it "should for dir_foreach" do
361
+ dir = FSPath('.')
362
+ dir.stub(:warn)
363
+ dir.dir_foreach do |entry|
364
+ fspath? entry
365
+ end
366
+ end if FSPath.method_defined?(:dir_foreach)
367
+
368
+ it "should for each_child" do
369
+ fspaths? FSPath('.').each_child
370
+ fspaths? FSPath('.').each_child do |child|
371
+ fspath? child
372
+ end
373
+ end if FSPath.method_defined?(:each_child)
374
+
375
+ it "should for each_entry" do
376
+ FSPath('.').each_entry do |entry|
377
+ fspath? entry
378
+ end
379
+ end
380
+
381
+ it "should for entries" do
382
+ fspaths? FSPath('.').entries
383
+ end
384
+
385
+ it "should for find" do
386
+ FSPath('.').find do |path|
387
+ fspath? path
388
+ end
389
+ end
390
+
391
+ it "should for inspect" do
392
+ FSPath('a').inspect.should include('FSPath')
393
+ end
394
+ end
255
395
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fspath
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-06 00:00:00.000000000 Z
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec