Class: TxghServer::Webhooks::Github::PushAttributes
- Inherits:
-
Object
- Object
- TxghServer::Webhooks::Github::PushAttributes
- Defined in:
- lib/txgh-server/webhooks/github/push_attributes.rb
Constant Summary collapse
- ATTRIBUTES =
[ :repo_name, :ref, :before, :after, :added_files, :modified_files, :author ]
Class Method Summary collapse
- .added_files(payload) ⇒ Object
- .after(payload) ⇒ Object
- .author(payload) ⇒ Object
- .before(payload) ⇒ Object
- .extract_files(payload, state) ⇒ Object
- .from_webhook_payload(payload) ⇒ Object
- .modified_files(payload) ⇒ Object
- .ref(payload) ⇒ Object
- .repo_name(payload) ⇒ Object
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(options = {}) ⇒ PushAttributes
constructor
A new instance of PushAttributes.
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ PushAttributes
Returns a new instance of PushAttributes.
60 61 62 63 64 65 66 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 60 def initialize( = {}) ATTRIBUTES.each do |attr| instance_variable_set( "@#{attr}", .fetch(attr) { .fetch(attr.to_s) } ) end end |
Class Method Details
.added_files(payload) ⇒ Object
37 38 39 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 37 def added_files(payload) extract_files(payload, 'added') end |
.after(payload) ⇒ Object
33 34 35 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 33 def after(payload) payload.fetch('after') end |
.author(payload) ⇒ Object
45 46 47 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 45 def (payload) payload.fetch('head_commit').fetch('committer').fetch('name') end |
.before(payload) ⇒ Object
29 30 31 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 29 def before(payload) payload.fetch('before') end |
.extract_files(payload, state) ⇒ Object
49 50 51 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 49 def extract_files(payload, state) payload.fetch('commits').flat_map { |c| c[state] }.uniq end |
.from_webhook_payload(payload) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 13 def from_webhook_payload(payload) new( ATTRIBUTES.each_with_object({}) do |attr, ret| ret[attr] = public_send(attr, payload) end ) end |
.modified_files(payload) ⇒ Object
41 42 43 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 41 def modified_files(payload) extract_files(payload, 'modified') end |
.ref(payload) ⇒ Object
25 26 27 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 25 def ref(payload) payload.fetch('ref') end |
.repo_name(payload) ⇒ Object
21 22 23 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 21 def repo_name(payload) payload.fetch('repository').fetch('full_name') end |
Instance Method Details
#files ⇒ Object
54 55 56 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 54 def files @files ||= added_files + modified_files end |
#to_h ⇒ Object
68 69 70 71 72 |
# File 'lib/txgh-server/webhooks/github/push_attributes.rb', line 68 def to_h ATTRIBUTES.each_with_object({}) do |attr, ret| ret[attr] = public_send(attr) end end |