Class: GithubHook
- Inherits:
-
Object
- Object
- GithubHook
- Defined in:
- lib/github_hook.rb
Constant Summary collapse
- VERSION =
'0.6.2'
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#commits ⇒ Object
readonly
Returns the value of attribute commits.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #create_commits(payload) ⇒ Object
-
#initialize(json) ⇒ GithubHook
constructor
A new instance of GithubHook.
- #last_commit ⇒ Object
- #parse_private_flag(private_flag) ⇒ Object
Constructor Details
#initialize(json) ⇒ GithubHook
Returns a new instance of GithubHook.
9 10 11 12 13 14 15 16 |
# File 'lib/github_hook.rb', line 9 def initialize(json) payload = JSON.parse(json) @before, @after, @ref = payload["before"], payload["after"], payload["ref"] @repository = OpenStruct.new(payload["repository"]) @repository.private = parse_private_flag(@repository.private) @owner = OpenStruct.new(payload["repository"]["owner"]) @commits = create_commits(payload) end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def after @after end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def before @before end |
#commits ⇒ Object (readonly)
Returns the value of attribute commits.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def commits @commits end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def owner @owner end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def ref @ref end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/github_hook.rb', line 7 def repository @repository end |
Instance Method Details
#create_commits(payload) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/github_hook.rb', line 22 def create_commits(payload) payload['commits'].map do |hash| commit_ostruct = OpenStruct.new(hash) commit_ostruct.sha = hash["id"] commit_ostruct. = OpenStruct.new(hash["author"]) commit_ostruct end rescue NoMethodError payload['commits'].map do |sha, hash| commit_ostruct = OpenStruct.new(hash) commit_ostruct.sha = sha commit_ostruct. = OpenStruct.new(hash["author"]) commit_ostruct end end |
#last_commit ⇒ Object
38 39 40 |
# File 'lib/github_hook.rb', line 38 def last_commit @commits.sort_by { |commit| commit. }.last end |
#parse_private_flag(private_flag) ⇒ Object
18 19 20 |
# File 'lib/github_hook.rb', line 18 def parse_private_flag(private_flag) private_flag == "true" ? true : false end |