Class: TestBench::ExpandPath
- Inherits:
-
Object
- Object
- TestBench::ExpandPath
- Defined in:
- lib/test_bench/expand_path.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#exclude_pattern ⇒ Object
readonly
Returns the value of attribute exclude_pattern.
-
#root_directory ⇒ Object
readonly
Returns the value of attribute root_directory.
Class Method Summary collapse
Instance Method Summary collapse
- #call(pattern) ⇒ Object
- #expand(full_pattern) ⇒ Object
-
#initialize(root_directory, exclude_pattern, dir) ⇒ ExpandPath
constructor
A new instance of ExpandPath.
Constructor Details
#initialize(root_directory, exclude_pattern, dir) ⇒ ExpandPath
7 8 9 10 11 |
# File 'lib/test_bench/expand_path.rb', line 7 def initialize root_directory, exclude_pattern, dir @dir = dir @exclude_pattern = exclude_pattern @root_directory = root_directory end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
3 4 5 |
# File 'lib/test_bench/expand_path.rb', line 3 def dir @dir end |
#exclude_pattern ⇒ Object (readonly)
Returns the value of attribute exclude_pattern.
4 5 6 |
# File 'lib/test_bench/expand_path.rb', line 4 def exclude_pattern @exclude_pattern end |
#root_directory ⇒ Object (readonly)
Returns the value of attribute root_directory.
5 6 7 |
# File 'lib/test_bench/expand_path.rb', line 5 def root_directory @root_directory end |
Class Method Details
.build(root_directory, exclude_pattern = nil, dir: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/test_bench/expand_path.rb', line 13 def self.build root_directory, exclude_pattern=nil, dir: nil dir ||= Dir exclude_pattern ||= Settings.toplevel.exclude_pattern exclude_pattern = Regexp.new exclude_pattern if exclude_pattern.is_a? String root_directory = Pathname root_directory new root_directory, exclude_pattern, dir end |
Instance Method Details
#call(pattern) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/test_bench/expand_path.rb', line 24 def call pattern full_pattern = root_directory.join pattern if dir.exist? full_pattern full_pattern = full_pattern.join '**/*.rb' end full_pattern.to_s end |
#expand(full_pattern) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/test_bench/expand_path.rb', line 34 def full_pattern dir[full_pattern].flat_map do |file| if exclude_pattern.match file [] else [file] end end end |