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.



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

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

Instance Attribute Details

#pathnameObject (readonly)

Returns the value of attribute pathname.



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

def pathname
  @pathname
end

Instance Method Details

#==(other) ⇒ Object



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

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

#dirnamesObject



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

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

#filenameObject



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

def filename
  basename(extname)
end

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

Returns:

  • (Boolean)


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

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



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

def reversed_dirnames
  @reversed_dirnames ||= dirnames.reverse
end

#similarity_score(file) ⇒ Object



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

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

#test?(test_directories: nil) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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