Class: TxghServer::Webhooks::Git::PushAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh-server/webhooks/git/push_attributes.rb

Constant Summary collapse

ATTRIBUTES =
[
  :event, :repo_name, :ref, :before, :after,
  :added_files, :modified_files, :author
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PushAttributes

Returns a new instance of PushAttributes.



46
47
48
49
50
51
52
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 46

def initialize(options = {})
  ATTRIBUTES.each do |attr|
    instance_variable_set(
      "@#{attr}", options.fetch(attr) { options.fetch(attr.to_s) }
    )
  end
end

Class Method Details

.after(payload) ⇒ Object



31
32
33
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 31

def after(payload)
  payload.fetch('after')
end

.before(payload) ⇒ Object



27
28
29
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 27

def before(payload)
  payload.fetch('before')
end

.event(payload) ⇒ Object



19
20
21
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 19

def event(payload)
  'push'
end

.from_webhook_payload(payload) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 11

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



35
36
37
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 35

def modified_files(payload)
  extract_files(payload, 'modified')
end

.ref(payload) ⇒ Object



23
24
25
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 23

def ref(payload)
  payload.fetch('ref')
end

Instance Method Details

#filesObject



40
41
42
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 40

def files
  @files ||= added_files + modified_files
end

#to_hObject



54
55
56
57
58
# File 'lib/txgh-server/webhooks/git/push_attributes.rb', line 54

def to_h
  ATTRIBUTES.each_with_object({}) do |attr, ret|
    ret[attr] = public_send(attr)
  end
end