Class: GitReport::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit = nil, project_identifier = nil) ⇒ Commit

Returns a new instance of Commit.



7
8
9
10
11
# File 'lib/commit.rb', line 7

def initialize commit = nil, project_identifier = nil
  @project            = GitReport.project
  @commit             = commit
  @project_identifier = project_identifier
end

Instance Attribute Details

#commitObject

Returns the value of attribute commit.



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

def commit
  @commit
end

#project_identifierObject

Returns the value of attribute project_identifier.



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

def project_identifier
  @project_identifier
end

Instance Method Details

#authorObject

returns a chached struct containing author information name and email of that commit



34
35
36
# File 'lib/commit.rb', line 34

def author
  @author ||= get_author
end

#batch_dataObject



58
59
60
# File 'lib/commit.rb', line 58

def batch_data
  @data ||= aggregate(:batch)
end

#dataObject

return the commits aggregated data in case a single commit is transferred



54
55
56
# File 'lib/commit.rb', line 54

def data
  @data ||= aggregate(:single)
end

#get_authorObject

returns the author struct fr the first time



39
40
41
42
43
44
# File 'lib/commit.rb', line 39

def get_author
  author = OpenStruct.new
  author.name = inner_author.name
  author.email = inner_author.email
  author
end

#messageObject

returns the commit message of self



24
25
26
# File 'lib/commit.rb', line 24

def message
  @commit.message
end

#shaObject

returns the commit hash of self



14
15
16
# File 'lib/commit.rb', line 14

def sha
  @commit.sha
end

#short_shaObject

returns the short version of the commit hash of self



19
20
21
# File 'lib/commit.rb', line 19

def short_sha
  self.sha[0..6]
end

#statsObject

returns commits stats in more detail



47
48
49
50
51
# File 'lib/commit.rb', line 47

def stats
  @commit.parent.diff(@commit).stats[:total]
rescue
  nil
end

#timeObject

returns the time when self was committed



29
30
31
# File 'lib/commit.rb', line 29

def time
  Time.parse(inner_author.date.to_s)
end

#to_jsonObject

return the commits aggregated data as JSON



63
64
65
# File 'lib/commit.rb', line 63

def to_json
  data.to_json
end