fedux_org-stdlib 0.8.11 → 0.9.0

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: 1e31a82df3298845b3873de282960a7db936423b
4
- data.tar.gz: 65e33b51505ae347bc8c5078d376c6d723145d35
3
+ metadata.gz: a8ea2539aca02e286fba494301df890c97c51997
4
+ data.tar.gz: 50ce0223035ded9a8df1874530ecd5efe02f7dff
5
5
  SHA512:
6
- metadata.gz: cf8da3ab201f5f3f5853a038d91008d22a1a18fdbefd67cfeb7c1079cd168e220fa80c0e846ca6450a10d669563d9629745a652c60c3870629e0c63005cb52f8
7
- data.tar.gz: 00b2e8d9a1867c94714452447a11289f317b785790e9a99d4f2a9f556e398c18d8b8451a0af38be09672dac3d13834023895b2794995b123429cf26531c38b62
6
+ metadata.gz: 673fab131735338339eca8e7aa2378b9e2db1fd8151ea2ebcc7dcebdadc6ba79649e6a8f1d29fe4cfb57a71ed10fae34db032b5de5dc0f640512707c0d854872
7
+ data.tar.gz: d7a0e36de2ec5c42ab178a7be419d8bea7494a339a7985ac4f4c5c40113ad6178f4c6d5d3317a1d5c5b9981956e538abec45a2c8ee56ddbe85e9534ebe0d4050
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.8.10)
4
+ fedux_org-stdlib (0.8.11)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -60,7 +60,7 @@ GEM
60
60
  erubis (2.7.0)
61
61
  facter (2.2.0)
62
62
  CFPropertyList (~> 2.2.6)
63
- ffi (1.9.5)
63
+ ffi (1.9.6)
64
64
  filegen (0.4.3)
65
65
  activesupport
66
66
  fuubar (2.0.0)
@@ -78,12 +78,12 @@ GEM
78
78
  mail (2.6.1)
79
79
  mime-types (>= 1.16, < 3)
80
80
  method_source (0.8.2)
81
- mime-types (2.4.1)
81
+ mime-types (2.4.3)
82
82
  minitest (5.4.2)
83
83
  multi_json (1.10.1)
84
84
  multi_test (0.1.1)
85
- netrc (0.7.7)
86
- parser (2.2.0.pre.5)
85
+ netrc (0.8.0)
86
+ parser (2.2.0.pre.6)
87
87
  ast (>= 1.1, < 3.0)
88
88
  slop (~> 3.4, >= 3.4.5)
89
89
  posix-spawn (0.3.9)
@@ -100,7 +100,7 @@ GEM
100
100
  yard (~> 0.8)
101
101
  rainbow (2.0.0)
102
102
  rake (10.3.2)
103
- redcarpet (3.1.2)
103
+ redcarpet (3.2.0)
104
104
  rest-client (1.7.2)
105
105
  mime-types (>= 1.16, < 3.0)
106
106
  netrc (~> 0.7)
@@ -108,7 +108,7 @@ GEM
108
108
  rspec-core (~> 3.1.0)
109
109
  rspec-expectations (~> 3.1.0)
110
110
  rspec-mocks (~> 3.1.0)
111
- rspec-core (3.1.6)
111
+ rspec-core (3.1.7)
112
112
  rspec-support (~> 3.1.0)
113
113
  rspec-expectations (3.1.2)
114
114
  diff-lcs (>= 1.2.0, < 2.0)
@@ -150,7 +150,7 @@ GEM
150
150
  versionomy (0.4.4)
151
151
  blockenspiel (>= 0.4.5)
152
152
  xml-simple (1.1.4)
153
- yard (0.8.7.4)
153
+ yard (0.8.7.6)
154
154
 
155
155
  PLATFORMS
156
156
  ruby
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/require_files'
3
+ require 'fedux_org_stdlib/logging/logger'
4
+
5
+ require_library %w(pathname)
6
+
7
+ module FeduxOrgStdlib
8
+ class RecursiveFileFinder
9
+ # Create a new instance of finder
10
+ #
11
+ # It tries to find a file.
12
+ #
13
+ # @param [String] file_name
14
+ # The name of the file to be looked for
15
+ #
16
+ # @param [String] working_directory
17
+ # The directory where to start search
18
+ #
19
+ # @return [RecursiveFileFinder]
20
+ # The config instance. If the resulting data structure created by the
21
+ # config_engine does not respond to `:[]` an empty config object will be
22
+ # created.
23
+
24
+ attr_reader :working_directory, :logger, :file_name, :raise_error
25
+
26
+ def initialize(
27
+ file_name:,
28
+ working_directory: Dir.getwd,
29
+ logger: FeduxOrgStdlib::Logging::Logger.new,
30
+ raise_error: true
31
+ )
32
+ @logger = logger
33
+ @working_directory = Pathname.new(working_directory).expand_path
34
+ @file_name = Pathname.new(file_name)
35
+ @raise_error = raise_error
36
+ end
37
+
38
+ # Return path to file
39
+ #
40
+ # @raise [Errno::ENOENT]
41
+ # If file cannot be found
42
+ #
43
+ # @return [Pathname]
44
+ # The path
45
+ def file
46
+ return @found_path if @found_path
47
+
48
+ @found_path = nil
49
+
50
+ working_directory.ascend do |p|
51
+ path = p + file_name
52
+ @found_path = path if path.exist?
53
+ end
54
+
55
+ return @found_path if @found_path
56
+ fail Errno::ENOENT, file_name.to_s if raise_error
57
+
58
+ nil
59
+ end
60
+
61
+ # The directory where file was found
62
+ #
63
+ # @raise [Errno::ENOENT]
64
+ # If file cannot be found
65
+ #
66
+ # @return [Pathname]
67
+ # The path to directory
68
+ def directory
69
+ file.dirname
70
+ end
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.8.11'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'fedux_org_stdlib/recursive_file_finder'
4
+
5
+ RSpec.describe RecursiveFileFinder do
6
+ context '#file' do
7
+ it 'returns path to found file' do
8
+ touch_file 'test.txt'
9
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('.'))
10
+ expect(finder.file).to eq Pathname.new(absolute_path('test.txt'))
11
+ end
12
+
13
+ it 'runs up file hierarchy' do
14
+ touch_file 'test.txt'
15
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
16
+ expect(finder.file).to eq Pathname.new(absolute_path('test.txt'))
17
+ end
18
+
19
+ it 'runs up file hierarchy and finds it in between' do
20
+ touch_file 'dir1/test.txt'
21
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
22
+ expect(finder.file).to eq Pathname.new(absolute_path('dir1/test.txt'))
23
+ end
24
+
25
+ it 'fails if file was not found' do
26
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
27
+ expect { finder.file }.to raise_error Errno::ENOENT
28
+ end
29
+
30
+ it 'returns nil if told to to so' do
31
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'), raise_error: false)
32
+ expect(finder.file).to be nil
33
+ end
34
+ end
35
+
36
+ context '#directory' do
37
+ it 'returns the directory where the file was found' do
38
+ touch_file 'test.txt'
39
+ finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
40
+ expect(finder.directory).to eq Pathname.new(absolute_path('.'))
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.11
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -146,6 +146,7 @@ files:
146
146
  - lib/fedux_org_stdlib/rake_tasks/tests/cucumber.rb
147
147
  - lib/fedux_org_stdlib/rake_tasks/tests/rspec.rb
148
148
  - lib/fedux_org_stdlib/rake_tasks/tests/travis.rb
149
+ - lib/fedux_org_stdlib/recursive_file_finder.rb
149
150
  - lib/fedux_org_stdlib/require_files.rb
150
151
  - lib/fedux_org_stdlib/roles/comparable_by_name.rb
151
152
  - lib/fedux_org_stdlib/roles/typable.rb
@@ -206,6 +207,7 @@ files:
206
207
  - spec/project/plan_spec.rb
207
208
  - spec/project/report_spec.rb
208
209
  - spec/project/taskjuggler_spec.rb
210
+ - spec/recursive_file_finder_spec.rb
209
211
  - spec/roles/typable_spec.rb
210
212
  - spec/shell_language_detector_spec.rb
211
213
  - spec/spec_helper.rb
@@ -287,6 +289,7 @@ test_files:
287
289
  - spec/project/plan_spec.rb
288
290
  - spec/project/report_spec.rb
289
291
  - spec/project/taskjuggler_spec.rb
292
+ - spec/recursive_file_finder_spec.rb
290
293
  - spec/roles/typable_spec.rb
291
294
  - spec/shell_language_detector_spec.rb
292
295
  - spec/spec_helper.rb