Class: Retest::MatchingOptions::Path

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/retest/matching_options/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Path

Returns a new instance of Path.



12
13
14
# File 'lib/retest/matching_options/path.rb', line 12

def initialize(path)
  @pathname = Pathname(path)
end

Instance Attribute Details

#pathnameObject (readonly)

Returns the value of attribute pathname.



11
12
13
# File 'lib/retest/matching_options/path.rb', line 11

def pathname
  @pathname
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/retest/matching_options/path.rb', line 16

def ==(other)
  pathname == other.pathname
end

#dirnamesObject



24
25
26
# File 'lib/retest/matching_options/path.rb', line 24

def dirnames
  @dirnames ||= dirname.each_filename.to_a
end

#filenameObject



49
50
51
# File 'lib/retest/matching_options/path.rb', line 49

def filename
  basename(extname)
end

#possible_test?(file, test_directories: nil) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/retest/matching_options/path.rb', line 36

def possible_test?(file, test_directories: nil)
  if test?(test_directories: test_directories)
    other = Path.new(file)
    self == other || test_subset?(other)
  else
    possible_test_regexs.any? { |regex| regex =~ file }
  end
end

#reversed_dirnamesObject



20
21
22
# File 'lib/retest/matching_options/path.rb', line 20

def reversed_dirnames
  @reversed_dirnames ||= dirnames.reverse
end

#similarity_score(file) ⇒ Object



45
46
47
# File 'lib/retest/matching_options/path.rb', line 45

def similarity_score(file)
  String::Similarity.levenshtein(to_s, file)
end

#test?(test_directories: nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/retest/matching_options/path.rb', line 28

def test?(test_directories: nil)
  if test_directories && (test_directories & dirnames).empty?
    return false
  end

  test_regexs.any? { |regex| regex =~ to_s }
end