class TestBench::Controls::DirSubstitute
Attributes
files[R]
Public Class Methods
example()
click to toggle source
# 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
new(files)
click to toggle source
# File lib/test_bench/controls/dir_substitute.rb, line 16 def initialize files @files = files end
Public Instance Methods
[](pattern)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/test_bench/controls/dir_substitute.rb, line 53 def exist? directory directories.include? directory.to_s end