rubypath 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51f0799c1640f582b159084204c9e6e5168035fe
4
- data.tar.gz: fa1da61036178cc9ad188abc93fd9016b468f0a2
3
+ metadata.gz: f4d517017d2e21a8fc5e59485e285f19cede540d
4
+ data.tar.gz: d978363e7ce770913f83b02c13ab41799f04e6b3
5
5
  SHA512:
6
- metadata.gz: 6092c75e0ea5910bd2b6cea271064e1354c74c06828612c90d6a10c56e53bdd7cf31d146f433e15624784eadde489ae1b026cb69c2b99521cf8c648cc63991c4
7
- data.tar.gz: eee9ea6c5f903366017db9f2368455bad3d2e541d9b2d8ccc6d7ca31e180013888832918a647380c0bcfa62920054858181d25c42f6e6aa516b167e62585035d
6
+ metadata.gz: e9b2defbdf58415d76e6d2cb8d4902eca1845ba71d1ffb237ebbd11699eb11bead4317735286dadb53c31d07cb72165d4afecc2d3de0ccf142ec586d2f609d1a
7
+ data.tar.gz: 7f54b7a30c7a56af8ecd10943672b7ba550cd526d8b51874772b683bc3118ef9aadcca16fc7487288447f35f1f83b4c41a072e751cbbd81c46e5d52f2beb10e9
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Ruby Path
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rubypath.svg)](http://badge.fury.io/rb/rubypath)
4
+ [![Build Status](http://img.shields.io/travis/jgraichen/rubypath/master.svg)](https://travis-ci.org/jgraichen/rubypath)
5
+ [![Coverage Status](http://img.shields.io/coveralls/jgraichen/rubypath/master.svg)](https://coveralls.io/r/jgraichen/rubypath)
6
+ [![Dependency Status](http://img.shields.io/gemnasium/jgraichen/rubypath.svg)](https://gemnasium.com/jgraichen/rubypath)
7
+ [![RubyDoc Documentation](http://img.shields.io/badge/rubydoc-here-blue.svg)](http://rubydoc.info/github/jgraichen/rubypath/master/frames)
8
+
3
9
  *Ruby Path* introduces a global `Path` class unifying most `File`, `Dir`, `FileUtils`, `Pathname` and `IO` operations with a flexible and powerful Object-Interface and still adding new useful methods and functions like mocking a while file system for fast and reliable testing.
4
10
 
5
11
  ## Installation
@@ -10,7 +16,7 @@ Add `rubypath` to your Gemfile, `gemspec` or install manually.
10
16
 
11
17
  Using `Path` with file and directory methods:
12
18
 
13
- ```
19
+ ```ruby
14
20
  base = Path '/path/to/base'
15
21
  src = base.mkpath 'project/src'
16
22
  src.touch 'Rakefile'
@@ -20,7 +26,7 @@ src.mkdir('lib').mkdir('mylib').touch('version.rb')
20
26
 
21
27
  Using IO:
22
28
 
23
- ```
29
+ ```ruby
24
30
  src.write "module Mylib\n VERSION = '0.1.0'\nend"
25
31
 
26
32
  src.lookup('project.yml').read
@@ -31,7 +37,7 @@ src.lookup('project.yml').read
31
37
 
32
38
  Wrap specific or just all specs in a virtual filesystem:
33
39
 
34
- ```
40
+ ```ruby
35
41
  # spec_helper.rb
36
42
 
37
43
  config.around(:each) do |example|
@@ -50,6 +50,8 @@ class Path::Backend
50
50
  raise Errno::EISDIR.new path
51
51
  rescue Errno::ENOTDIR
52
52
  raise Errno::ENOTDIR.new path
53
+ rescue Errno::EACCES
54
+ raise Errno::EACCES.new path
53
55
  end
54
56
 
55
57
  ## OPERATIONS
@@ -10,13 +10,25 @@ class Path
10
10
  new Backend.instance.getwd
11
11
  end
12
12
 
13
- def glob(pattern, flags = ::File::FNM_EXTGLOB)
13
+ def glob(pattern, flags = nil)
14
+ flags = default_glob_flags(flags)
15
+
14
16
  if block_given?
15
17
  Backend.instance.glob(pattern, flags) {|path| yield Path path }
16
18
  else
17
19
  Backend.instance.glob(pattern, flags).map(&Path)
18
20
  end
19
21
  end
22
+
23
+ # @!visibility private
24
+ #
25
+ def default_glob_flags(flags)
26
+ if flags.nil? && defined?(::File::FNM_EXTGLOB)
27
+ ::File::FNM_EXTGLOB
28
+ else
29
+ flags.to_i
30
+ end
31
+ end
20
32
  end
21
33
 
22
34
  # Create directory.
@@ -64,7 +76,7 @@ class Path
64
76
  end
65
77
 
66
78
  #
67
- def glob(pattern, flags = ::File::FNM_EXTGLOB, &block)
79
+ def glob(pattern, flags = nil, &block)
68
80
  Path.glob(::File.join(escaped_glob_path, pattern), flags, &block)
69
81
  end
70
82
 
@@ -79,7 +79,9 @@ class Path
79
79
  # Defaults to `File::FNM_EXTGLOB`.
80
80
  # @return [Path] Path to found file or nil.
81
81
  #
82
- def lookup(pattern, flags = ::File::FNM_EXTGLOB)
82
+ def lookup(pattern, flags = nil)
83
+ flags = self.class.default_glob_flags(flags)
84
+
83
85
  expand.ascend do |path|
84
86
  case pattern
85
87
  when String
@@ -2,7 +2,7 @@ class Path
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
8
8
 
@@ -26,9 +26,11 @@ describe Path do
26
26
  /lib/path/file.rb /lib/path/ext.rb)
27
27
  end
28
28
 
29
- it 'should return matching files (III)' do
30
- expect(subject.call('/**/{dir,ext}.rb')).to match_array \
31
- %w(/lib/path/dir.rb /lib/path/ext.rb)
29
+ if defined?(::File::FNM_EXTGLOB)
30
+ it 'should return matching files (III)' do
31
+ expect(subject.call('/**/{dir,ext}.rb')).to match_array \
32
+ %w(/lib/path/dir.rb /lib/path/ext.rb)
33
+ end
32
34
  end
33
35
 
34
36
  it 'should return matching files (IV)' do
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Path do
4
+ let(:delta) { 1.0 }
5
+
4
6
  describe 'File Operations' do
5
7
  with_backends :mock, :sys do
6
8
  let(:path) { Path('/path/to/file.txt') }
@@ -28,7 +30,7 @@ describe Path do
28
30
 
29
31
  it 'should update modification time' do
30
32
  subject
31
- expect(expected_path.mtime).to be_within(1).of(Time.now)
33
+ expect(expected_path.mtime).to be_within(delta).of(Time.now)
32
34
  end
33
35
  end
34
36
 
@@ -76,7 +78,7 @@ describe Path do
76
78
 
77
79
  it 'should should update modification time' do
78
80
  subject
79
- expect(path.mtime).to be_within(1).of(Time.now)
81
+ expect(path.mtime).to be_within(delta).of(Time.now)
80
82
  end
81
83
  end
82
84
 
@@ -209,10 +211,12 @@ describe Path do
209
211
  .to eq path.join('a/config.yml').expand
210
212
  end
211
213
 
212
- it 'should find first file that match (II)' do
213
- expect(path.join('a/b')
214
- .send(described_method, 'config.{yml,yaml}'))
215
- .to eq path.join('a/config.yml').expand
214
+ if defined?(::File::FNM_EXTGLOB)
215
+ it 'should find first file that match (II)' do
216
+ expect(path.join('a/b')
217
+ .send(described_method, 'config.{yml,yaml}'))
218
+ .to eq path.join('a/config.yml').expand
219
+ end
216
220
  end
217
221
 
218
222
  it 'should find first file that dotmatch' do
@@ -257,7 +261,7 @@ describe Path do
257
261
  subject { path.send described_method }
258
262
 
259
263
  it 'should return file modification time' do
260
- should be_within(0.1).of(Time.now)
264
+ should be_within(delta).of(Time.now)
261
265
  end
262
266
 
263
267
  context 'with modification time changed' do
@@ -286,7 +290,7 @@ describe Path do
286
290
  context 'new create file' do
287
291
  before { path.touch }
288
292
 
289
- it { should be_within(0.1).of(Time.now) }
293
+ it { should be_within(delta).of(Time.now) }
290
294
  end
291
295
 
292
296
  context 'with existing file' do
@@ -296,7 +300,7 @@ describe Path do
296
300
  before { path.touch }
297
301
  before { sleep 0.3 }
298
302
 
299
- it { should be_within(0.1).of(Time.now - 0.3) }
303
+ it { should be_within(delta).of(Time.now - 0.3) }
300
304
  end
301
305
 
302
306
  context 'and changed access time' do
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Path do
4
+ let(:delta) { 1.0 }
5
+
4
6
  describe 'IO Operations' do
5
7
  with_backends :mock, :sys do
6
8
 
@@ -18,7 +20,7 @@ describe Path do
18
20
 
19
21
  it 'should update access time' do
20
22
  subject
21
- expect(path.atime).to be_within(0.1).of(Time.now)
23
+ expect(path.atime).to be_within(delta).of(Time.now)
22
24
  end
23
25
 
24
26
  context 'with read length and offset' do
@@ -80,7 +82,7 @@ describe Path do
80
82
 
81
83
  it 'should update mtime' do
82
84
  expect{ subject }.to change{ path.mtime }
83
- expect(path.mtime).to be_within(0.1).of(Time.now)
85
+ expect(path.mtime).to be_within(delta).of(Time.now)
84
86
  end
85
87
 
86
88
  it 'should not update atime' do
@@ -112,12 +114,12 @@ describe Path do
112
114
 
113
115
  it 'should set mtime' do
114
116
  subject
115
- expect(path.mtime).to be_within(0.1).of(Time.now)
117
+ expect(path.mtime).to be_within(delta).of(Time.now)
116
118
  end
117
119
 
118
120
  it 'should set atime' do
119
121
  subject
120
- expect(path.atime).to be_within(0.1).of(Time.now)
122
+ expect(path.atime).to be_within(delta).of(Time.now)
121
123
  end
122
124
  end
123
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-16 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler