Class: Github::Commit

Inherits:
OpenStruct show all
Defined in:
lib/github.rb

Constant Summary collapse

ATTR_NAMES =
[:commit, :message, :branch, :committed_at, :committer_name, :committer_email, :author_name, :author_email, :compare_url]

Instance Method Summary collapse

Methods inherited from OpenStruct

#[], #[]=

Constructor Details

#initialize(data, repository) ⇒ Commit

Returns a new instance of Commit.



98
99
100
101
102
# File 'lib/github.rb', line 98

def initialize(data, repository)
  data['author'] ||= {}
  data['repository']  = repository
  super(data)
end

Instance Method Details

#authorObject



132
133
134
# File 'lib/github.rb', line 132

def author
  self['author'] || {}
end

#author_emailObject



140
141
142
# File 'lib/github.rb', line 140

def author_email
  author['email']
end

#author_nameObject



136
137
138
# File 'lib/github.rb', line 136

def author_name
  author['name']
end

#branchObject



112
113
114
# File 'lib/github.rb', line 112

def branch
  (self['ref'] || '').split('/').last
end

#commitObject



108
109
110
# File 'lib/github.rb', line 108

def commit
  self['id']
end

#committed_atObject



116
117
118
# File 'lib/github.rb', line 116

def committed_at
  self['timestamp']
end

#committerObject



120
121
122
# File 'lib/github.rb', line 120

def committer
  self['committer'] || {}
end

#committer_emailObject



128
129
130
# File 'lib/github.rb', line 128

def committer_email
  committer['email']
end

#committer_nameObject



124
125
126
# File 'lib/github.rb', line 124

def committer_name
  committer['name']
end

#compare_urlObject



144
145
146
# File 'lib/github.rb', line 144

def compare_url
  self['compare_url']
end

#to_hashObject



104
105
106
# File 'lib/github.rb', line 104

def to_hash
  ATTR_NAMES.inject({}) { |result, name| result.merge(name => self.send(name)) }
end