Class: Bugwatch::Commit

Inherits:
Object
  • Object
show all
Extended by:
Attrs
Includes:
RubyFileAdapter
Defined in:
lib/bugwatch/commit.rb

Defined Under Namespace

Classes: Stats

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attrs

attrs, lazy_attrs

Methods included from RubyFileAdapter

#analyzable_file?, #ruby_file?, #test_file?

Constructor Details

#initialize(attributes = {}) ⇒ Commit

Returns a new instance of Commit.



51
52
53
# File 'lib/bugwatch/commit.rb', line 51

def initialize(attributes={})
  @attributes = attributes
end

Class Method Details

.from_grit(grit) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/bugwatch/commit.rb', line 40

def self.from_grit(grit)
  author = grit.author
  committer = grit.committer
  stats = Enumerator.new {|y| grit.stats.files.each {|data| y << Stats.new(*data) } }
  diffs = Enumerator.new {|y| grit.diffs.each {|diff| y << Diff.from_grit(diff) } }
  tree = Tree.new(grit.tree)
  new sha: grit.sha, message: grit.short_message, diffs: diffs, stats: stats, tree: tree,
      author_name: author.name, author_email: author.email, authored_date: grit.authored_date,
      committer_name: committer.name, committer_email: committer.email, committed_date: grit.committed_date
end

Instance Method Details

#churn(lang = :ruby) ⇒ Object



69
70
71
72
# File 'lib/bugwatch/commit.rb', line 69

def churn(lang=:ruby)
  adapter = Bugwatch.adapters[lang]
  Churn.new(stats, adapter.file) if adapter
end

#complexity(lang = :ruby) ⇒ Object



64
65
66
67
# File 'lib/bugwatch/commit.rb', line 64

def complexity(lang=:ruby)
  adapter = Bugwatch.adapters[lang]
  adapter.complexity.new(diffs) if adapter && adapter.complexity
end

#filesObject



60
61
62
# File 'lib/bugwatch/commit.rb', line 60

def files
  @files ||= stats.map(&:file)
end

#identify(filename, line_number) ⇒ Object

TODO don’t use grit blob



75
76
77
78
# File 'lib/bugwatch/commit.rb', line 75

def identify(filename, line_number)
  blob = tree / filename
  blob ? MethodParser.find(blob.data, line_number..line_number) : {}
end