Module: GH::Events
- Extended by:
- Events
- Included in:
- Events
- Defined in:
- lib/gh/events.rb,
lib/gh/events/version.rb
Defined Under Namespace
Modules: Text
Classes: Error
Constant Summary
collapse
- PATH =
File.expand_path(File.join(%w(.. .. .. res events.yml)), __FILE__)
- HEURISTICS =
YAML.load_file(PATH)
- VERSION =
"0.8.3"
Instance Method Summary
collapse
Instance Method Details
#typeof(payload) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gh/events.rb', line 17
def typeof(payload)
payload = JSON.parse(payload) if payload.is_a?(String)
payload = payload.marshal_dump if payload.is_a?(OpenStruct)
payload = payload.deep_stringify_keys
keys = payload.keys
HEURISTICS.each do |type, characteristics|
x = ((characteristics['present'] || []) - keys)
next unless x.empty?
y = ((characteristics['absent'] || []) & keys)
next unless y.empty?
z = payload.dup.merge(characteristics['exactly'] || {}) == payload
next unless z
n = characteristics['number_of_keys'] &&
keys.count != characteristics['number_of_keys']
next if n
return type.to_sym
end
return :unknown
end
|