Class: Shiba::Review::Diff::FileDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/shiba/review/diff.rb

Constant Summary collapse

FILE_NAME_PATTERN =

+++ b/test/app/app.rb

/^\+\+\+ b\/(.*?)$/

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileDiff

Returns a new instance of FileDiff.



197
198
199
# File 'lib/shiba/review/diff.rb', line 197

def initialize(path)
  @path = path
end

Instance Method Details

#file(context: nil, ignore_deletions: nil) ⇒ Object



217
218
219
220
221
# File 'lib/shiba/review/diff.rb', line 217

def file(context: nil, ignore_deletions: nil)
  warn "Context not supported for file diffs" if context
  warn "Ignore deletions not supported for file diffs" if ignore_deletions
  File.open(@path)
end

#pathsObject

Extracts path names from the diff file

Example: index ade9b24..661d522 100644 — a/test/app/app.rb +++ b/test/app/app.rb @@ -24,4 +24,4 @@ ActiveRecord::Base… org = Organization.create!(name: ‘test’)

diff.paths

> [ test/app/app.rb ]



212
213
214
215
# File 'lib/shiba/review/diff.rb', line 212

def paths
  f = File.open(@path)
  f.grep(FILE_NAME_PATTERN) { $1 }
end