Class: Rfix::File::Tracked

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/rfix/file/tracked.rb

Constant Summary collapse

ID =
"[T]".color(:lightseagreen).freeze

Instance Method Summary collapse

Instance Method Details

#absolute_pathObject



20
21
22
# File 'lib/rfix/file/tracked.rb', line 20

def absolute_path
  repository.path.join(path)
end

#exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rfix/file/tracked.rb', line 24

def exists?
  true
end

#keyObject



16
17
18
# File 'lib/rfix/file/tracked.rb', line 16

def key
  absolute_path.to_s
end

#linesObject



50
51
52
53
54
55
# File 'lib/rfix/file/tracked.rb', line 50

def lines
  Diff.new(repository: repository, options: {
    paths: [path.to_path],
    disable_pathspec_match: true
  }).lines.lazy.map(&:new_lineno).select(&:positive?)
end

#to_sObject



32
33
34
# File 'lib/rfix/file/tracked.rb', line 32

def to_s
  "%s:%s" % [path, to_str_range]
end

#to_str_rangeObject



36
37
38
39
40
41
42
43
44
# File 'lib/rfix/file/tracked.rb', line 36

def to_str_range
  lines
    .to_a
    .sort
    .chunk_while { |i, j| i + 1 == j }
    .map { |a| a.length < 3 ? a : "#{a.first}-#{a.last}" }
    .join(",")
    .then { |res| res.empty? ? "-" : res }
end

#to_tableObject



46
47
48
# File 'lib/rfix/file/tracked.rb', line 46

def to_table
  [path, to_str_range]
end

#tracked?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rfix/file/tracked.rb', line 28

def tracked?
  true
end