everything-piece-find 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7147fc00389b0ef849dd1fc80ff964bbacdbd90a
4
- data.tar.gz: e8f6a0bb9c92ee543ec4f77268e36cee7dcf310d
3
+ metadata.gz: 0bc51892fa9eec98831db48565fe87f54f6b3df0
4
+ data.tar.gz: fc8c816292b00d49fc87f588e8c7eeff866d39c6
5
5
  SHA512:
6
- metadata.gz: c7022fe336ee00c63eb4ecd1a46b0786849c8af0efc34b9b88659caa1e454df8446add48f3aee162d64be794f5c3ec5fc9f1616f74d6731a60afe195dc342fa8
7
- data.tar.gz: ea029d60e82c8a7fc2a2b71eadd12a72fe2764793fcd70bd22c1d5164fde85b1575b72c6a42943302bf5da7997dfe12f202f7095f42fda49561beaa3f3464d0f
6
+ metadata.gz: 2e811ffc26a1c0bbe7807825ffbe3436b0ff75c9f15a3ac576a82c9bf324303f4387842985dc38e232fb6511c700629d09acca3067091d26790cb101e142b01f
7
+ data.tar.gz: 16ed575c9f06c814d5ad9bb645c17b65f8c6fdbad0453162e38b8f2253c533e9a94f70fa8dcd6df999da1f6aa41b60af5e6eb39438e9451ddc13b64545e7864f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ - Add #find_by_name_recursive to search for a piece within subdirectories
6
+ - Raise error in #find_by_name when file is found instead of dir
7
+
3
8
  ## 0.2.0
4
9
 
5
10
  - Raise error in #find_by_name when piece isn't found
@@ -1,7 +1,7 @@
1
1
  module Everything
2
2
  class Piece
3
3
  module Find
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -7,15 +7,42 @@ module Everything
7
7
  def find_by_name(piece_name)
8
8
  piece_path = File.join(Everything.path, piece_name)
9
9
 
10
- if Dir.exist?(piece_path)
11
- Piece.new(piece_path)
10
+ raise_no_piece_error(piece_name) unless File.exist?(piece_path)
11
+ raise_not_directory_error(piece_name, piece_path) unless Dir.exist?(piece_path)
12
12
 
13
- else
14
- error_message =
15
- %Q{No piece "#{piece_name}" found in "#{Everything.path}"}
13
+ Piece.new(piece_path)
14
+ end
15
+
16
+ def find_by_name_recursive(piece_name)
17
+ glob_path = File.join(Everything.path, '**', piece_name)
18
+ possible_dirs = Dir.glob(glob_path)
19
+ full_piece_path = possible_dirs.first
20
+
21
+ raise_no_piece_recursive_error(piece_name) unless full_piece_path
22
+ raise_not_directory_error(piece_name, full_piece_path) unless Dir.exist?(full_piece_path)
23
+
24
+ Piece.new(full_piece_path)
25
+ end
26
+
27
+ private
28
+
29
+ def raise_no_piece_error(piece_name)
30
+ error_message =
31
+ %Q{No piece "#{piece_name}" found in "#{Everything.path}"}
32
+
33
+ raise ArgumentError, error_message
34
+ end
35
+
36
+ def raise_no_piece_recursive_error(piece_name)
37
+ error_message =
38
+ %Q{No piece "#{piece_name}" found in "#{Everything.path}" or subdirectories}
39
+ raise ArgumentError, error_message
40
+ end
16
41
 
17
- raise ArgumentError, error_message
18
- end
42
+ def raise_not_directory_error(piece_name, piece_path)
43
+ error_message =
44
+ %Q{Found file "#{piece_name}" at "#{piece_path}", but was expecting a directory}
45
+ raise ArgumentError, error_message
19
46
  end
20
47
  end
21
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everything-piece-find
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Tolle