Class: Rfix::Repository
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Rfix::Repository
- Includes:
- Dry::Core::Constants, Dry::Core::Memoizable
- Defined in:
- lib/rfix/repository.rb
Constant Summary collapse
- INCLUDED =
[File::Untracked, File::Tracked].to_set.freeze
- INIT =
Hash.new { |h, k| h[k] = EMPTY_ARRAY.dup }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #cache ⇒ Object
- #collector ⇒ Object
- #deleted ⇒ Object
- #files ⇒ Object
- #ignored ⇒ Object
- #include_file?(path, line = Undefined) ⇒ Boolean (also: #contains?, #include?)
-
#origin ⇒ Object
TODO: Refactor.
- #path ⇒ Object
- #paths ⇒ Object
- #permitted ⇒ Object
- #skipped ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #tracked ⇒ Object
- #untracked ⇒ Object
Class Method Details
.method_added(name) ⇒ Object
26 27 28 |
# File 'lib/rfix/repository.rb', line 26 def self.method_added(name) super.tap { memoize(name) } end |
Instance Method Details
#cache ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rfix/repository.rb', line 58 def cache Concurrent::Map.new do |storage, path| storage.fetch(Types::Path::Absolute.call(path).to_s, File::Null) end.tap do |storage| files.each { |file| storage.compute_if_absent(file.key) { file } } end end |
#collector ⇒ Object
111 112 113 |
# File 'lib/rfix/repository.rb', line 111 def collector Collector.call(repository: self, reference: reference.name) end |
#deleted ⇒ Object
50 51 52 |
# File 'lib/rfix/repository.rb', line 50 def deleted files.select(&:deleted?) end |
#files ⇒ Object
66 67 68 69 70 |
# File 'lib/rfix/repository.rb', line 66 def files Diff.new(repository: self, current_path: current_path).deltas.map do |delta| File::Tracked.call(**delta.new_file, repository: self, status: delta.status) end end |
#ignored ⇒ Object
42 43 44 |
# File 'lib/rfix/repository.rb', line 42 def ignored files.select(&:ignored?) end |
#include_file?(path, line = Undefined) ⇒ Boolean Also known as: contains?, include?
95 96 97 98 99 |
# File 'lib/rfix/repository.rb', line 95 def include_file?(path, line = Undefined) return cache[path].exists? if line == Undefined cache[path].include?(line) end |
#origin ⇒ Object
TODO: Refactor
105 106 107 108 109 |
# File 'lib/rfix/repository.rb', line 105 def origin repository.lookup(repository.rev_parse(reference.name).oid) rescue Rugged::Error, Rugged::InvalidError, Rugged::ReferenceError raise Error, "Reference #{reference.name.inspect} not found" end |
#path ⇒ Object
54 55 56 |
# File 'lib/rfix/repository.rb', line 54 def path Pathname(workdir) end |
#paths ⇒ Object
91 92 93 |
# File 'lib/rfix/repository.rb', line 91 def paths permitted.map(&:key).to_a end |
#permitted ⇒ Object
72 73 74 |
# File 'lib/rfix/repository.rb', line 72 def permitted files end |
#skipped ⇒ Object
34 35 36 |
# File 'lib/rfix/repository.rb', line 34 def skipped ignored + deleted end |
#to_s ⇒ Object Also known as: inspect
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rfix/repository.rb', line 76 def to_s files.each_with_object(INIT.dup) do |file, object| object[file.class] << file end.map do |type, files| "%<type>s[%<count>i]:%<files>s" % { files: files.map(&:to_s).join(", "), type: type.name.demodulize, count: files.count } end.then do |types| "Repository<%<types>s>" % { types: types.join(", ") } end end |
#tracked ⇒ Object
38 39 40 |
# File 'lib/rfix/repository.rb', line 38 def tracked files.select(&:tracked?) end |
#untracked ⇒ Object
46 47 48 |
# File 'lib/rfix/repository.rb', line 46 def untracked files.select(&:untracked?) end |