Class: TestBench::Controls::DirSubstitute
- Inherits:
-
Object
- Object
- TestBench::Controls::DirSubstitute
- Defined in:
- lib/test_bench/controls/dir_substitute.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
Instance Method Summary collapse
- #[](pattern) ⇒ Object
- #directories ⇒ Object
- #exist?(directory) ⇒ Boolean
-
#initialize(files) ⇒ DirSubstitute
constructor
A new instance of DirSubstitute.
Constructor Details
#initialize(files) ⇒ DirSubstitute
Returns a new instance of DirSubstitute.
16 17 18 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 16 def initialize files @files = files end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
14 15 16 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 14 def files @files end |
Class Method Details
.example ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 4 def self.example files = %w( /root/some/path/1.rb /root/some/path/2.rb /root/other/path.rb ) new files end |
Instance Method Details
#[](pattern) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 20 def [] pattern if match_data = %r{\A(?<base>.*)/\*\*/\*\.rb\z}.match(pattern) # some/path/**/*.rb files.select do |file| file.start_with? match_data['base'] end elsif match_data = %r{\A(?<base>.*)/\*\.rb\z}.match(pattern) # some/path/*.rb files.select do |file| dirname = File.dirname file dirname == match_data['base'] end else # some/path.rb files.select do |file| file == pattern end end end |
#directories ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 40 def directories files.flat_map do |file| dirs = [] until file == '/' file = File.dirname file dirs << file end dirs end end |
#exist?(directory) ⇒ Boolean
53 54 55 |
# File 'lib/test_bench/controls/dir_substitute.rb', line 53 def exist? directory directories.include? directory.to_s end |