Class: Perkins::Commit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha, repo) ⇒ Commit

Returns a new instance of Commit.



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

def initialize(sha,  repo)
  return if sha.nil?
  @commit = repo.git.gcommit(sha)
  @sha = sha
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



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

def branch
  @branch
end

#shaObject (readonly)

Returns the value of attribute sha.



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

def sha
  @sha
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/perkins/commit.rb', line 29

def as_json(opts={})
  data = {}
  fields = [:author, :email, :created_at, :message, :sha]
  fields.each{|f| data[f] = send(f)}
  data
end

#authorObject



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

def author
  @commit.author.name unless @commit.blank?
end

#created_atObject



21
22
23
# File 'lib/perkins/commit.rb', line 21

def created_at
  @commit.author.date unless @commit.blank?
end

#emailObject



17
18
19
# File 'lib/perkins/commit.rb', line 17

def email
  @commit.author.email unless @commit.blank?
end

#messageObject



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

def message
  @commit.message unless @commit.blank?
end