Class: DiffParser::Diff

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/diff_parser/diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit, options) ⇒ Diff

Returns a new instance of Diff.



8
9
10
11
12
13
14
15
16
# File 'lib/diff_parser/diff.rb', line 8

def initialize(commit, options)
  @commit = commit
  @options = options
  @info = github.commit(repo, sha)

  @raw = Rails.cache.fetch(diff_cache_key) do
    raw_diff.force_encoding('UTF-8')
  end
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



5
6
7
# File 'lib/diff_parser/diff.rb', line 5

def commit
  @commit
end

#infoObject (readonly)

Returns the value of attribute info.



5
6
7
# File 'lib/diff_parser/diff.rb', line 5

def info
  @info
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/diff_parser/diff.rb', line 5

def options
  @options
end

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/diff_parser/diff.rb', line 5

def raw
  @raw
end

Instance Method Details

#diff_cache_keyObject



22
23
24
# File 'lib/diff_parser/diff.rb', line 22

def diff_cache_key
  "diff-#{repo}-#{sha}"
end

#filesObject



26
27
28
# File 'lib/diff_parser/diff.rb', line 26

def files
  DiffParser::DiffFilesCollection.new(self, options)
end

#raw_diffObject



18
19
20
# File 'lib/diff_parser/diff.rb', line 18

def raw_diff
  @raw_diff ||= github.commit(repo, sha, accept: 'application/vnd.github.VERSION.diff')
end