Class: Rfix::File::Tracked
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Rfix::File::Tracked
- Defined in:
- lib/rfix/file/tracked.rb
Constant Summary collapse
- ID =
"[T]".color(:lightseagreen).freeze
Instance Method Summary collapse
- #absolute_path ⇒ Object
- #exists? ⇒ Boolean
- #key ⇒ Object
- #lines ⇒ Object
- #to_s ⇒ Object
- #to_str_range ⇒ Object
- #to_table ⇒ Object
- #tracked? ⇒ Boolean
Instance Method Details
#absolute_path ⇒ Object
20 21 22 |
# File 'lib/rfix/file/tracked.rb', line 20 def absolute_path repository.path.join(path) end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/rfix/file/tracked.rb', line 24 def exists? true end |
#key ⇒ Object
16 17 18 |
# File 'lib/rfix/file/tracked.rb', line 16 def key absolute_path.to_s end |
#lines ⇒ Object
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_s ⇒ Object
32 33 34 |
# File 'lib/rfix/file/tracked.rb', line 32 def to_s "%s:%s" % [path, to_str_range] end |
#to_str_range ⇒ Object
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_table ⇒ Object
46 47 48 |
# File 'lib/rfix/file/tracked.rb', line 46 def to_table [path, to_str_range] end |
#tracked? ⇒ Boolean
28 29 30 |
# File 'lib/rfix/file/tracked.rb', line 28 def tracked? true end |