Skip to content

Commit

Permalink
deep symbolize keys on messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Jul 5, 2017
1 parent c1b0fd1 commit dfbd6ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/travis/hub/handler.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'travis/hub/helper/context'
require 'travis/hub/helper/hash'
require 'travis/hub/helper/string'
require 'travis/hub/service'

module Travis
module Hub
class Handler
include Helper::Context, Helper::String
include Helper::Context, Helper::Hash, Helper::String

attr_reader :context, :type, :event, :payload, :object

Expand Down Expand Up @@ -46,7 +47,7 @@ def normalize_event(event)
end

def normalize_payload(payload)
payload = payload.symbolize_keys
payload = deep_symbolize_keys(payload)
payload = normalize_state(payload)
normalize_timestamps(payload)
end
Expand Down
21 changes: 21 additions & 0 deletions lib/travis/hub/helper/hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Travis
module Hub
module Helper
module Hash
def deep_symbolize_keys(hash)
hash.map do |key, obj|
obj = case obj
when Array
obj.map { |obj| deep_symbolize_keys(obj) }
when ::Hash
deep_symbolize_keys(obj)
else
obj
end
[key.to_sym, obj]
end.to_h
end
end
end
end
end

0 comments on commit dfbd6ae

Please sign in to comment.