Class: Sanctify::Repo
- Inherits:
-
Object
- Object
- Sanctify::Repo
- Defined in:
- lib/sanctify/repo.rb
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #added_lines ⇒ Object
- #diff ⇒ Object
-
#initialize(args, ignored_paths: []) ⇒ Repo
constructor
A new instance of Repo.
Constructor Details
#initialize(args, ignored_paths: []) ⇒ Repo
Returns a new instance of Repo.
6 7 8 9 10 11 12 13 |
# File 'lib/sanctify/repo.rb', line 6 def initialize(args, ignored_paths: []) @path = args[:repo] @to = args[:to] # The default for `to` in git.diff is nil @from = args[:from] || 'HEAD' @git = Git.open(path) ignored_paths ||= [] @ignored_paths = ignored_paths.map { |pattern| Regexp.new(pattern) } end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
5 6 7 |
# File 'lib/sanctify/repo.rb', line 5 def git @git end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/sanctify/repo.rb', line 5 def path @path end |
Instance Method Details
#added_lines ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sanctify/repo.rb', line 22 def added_lines [].tap do |lines| diff.each do |f| next if f.type == 'deleted' next if should_ignore? f.path f.patch.split("\n").each do |line| # don't include leading '+' lines << [line[1..-1], f.path] if added_line? line end end end end |
#diff ⇒ Object
15 16 17 18 19 20 |
# File 'lib/sanctify/repo.rb', line 15 def diff # The diff processing is only done in the each method # so we'll call this method as a singleton so we don't accidentally # do this more than once per instance of the repo. @diff ||= git.diff(@from, @to).each.to_a end |