Class: Janky::GitHub::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/janky/github/payload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, branch, head, pusher, commits, compare) ⇒ Payload

Returns a new instance of Payload.



11
12
13
14
15
16
17
18
# File 'lib/janky/github/payload.rb', line 11

def initialize(uri, branch, head, pusher, commits, compare)
  @uri     = uri
  @branch  = branch
  @head    = head
  @pusher  = pusher
  @commits = commits
  @compare = compare
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def branch
  @branch
end

#commitsObject (readonly)

Returns the value of attribute commits.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def commits
  @commits
end

#compareObject (readonly)

Returns the value of attribute compare.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def compare
  @compare
end

#headObject (readonly)

Returns the value of attribute head.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def head
  @head
end

#pusherObject (readonly)

Returns the value of attribute pusher.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def pusher
  @pusher
end

#uriObject (readonly)

Returns the value of attribute uri.



20
21
22
# File 'lib/janky/github/payload.rb', line 20

def uri
  @uri
end

Class Method Details

.parse(json) ⇒ Object



4
5
6
7
8
9
# File 'lib/janky/github/payload.rb', line 4

def self.parse(json)
  parsed = PayloadParser.new(json)
  new(parsed.uri, parsed.branch, parsed.head, parsed.pusher,
      parsed.commits,
      parsed.compare)
end

Instance Method Details

#head_commitObject



22
23
24
25
26
# File 'lib/janky/github/payload.rb', line 22

def head_commit
  @commits.detect do |commit|
    commit.sha1 == @head
  end
end

#to_jsonObject



28
29
30
31
32
33
34
35
# File 'lib/janky/github/payload.rb', line 28

def to_json
  { :after   => @head,
    :ref     => "refs/heads/#{@branch}",
    :pusher  => {:name => @pusher},
    :uri     => @uri,
    :commits => @commits,
    :compare => @compare }.to_json
end