Skip to content

Commit

Permalink
ServerlessHandlerEventSources: json loading fixes
Browse files Browse the repository at this point in the history
- utilize the constant pointing to the JSON source file
- only read from the JSON source file once
  • Loading branch information
fallwith committed Aug 14, 2024
1 parent 420c374 commit 4677f2e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/new_relic/agent/serverless_handler_event_sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ module Agent
# Furthermore, `.length` calls are converted to Ruby `#size` notation to
# denote that a method call must be performed on the dug value.
class ServerlessHandlerEventSources
JSON_SOURCE = File.join(File.dirname(__FILE__), 'serverless_handler_event_sources.json')
JSON_SOURCE = File.join(File.dirname(__FILE__), 'serverless_handler_event_sources.json').freeze
JSON_RAW = JSON.parse(File.read(JSON_SOURCE)).freeze

def self.to_hash
hash = {}
raw = JSON.parse(File.read('lib/new_relic/agent/serverless_handler_event_sources.json'))
raw.each do |type, info|
JSON_RAW.each_with_object({}) do |(type, info), hash|
hash[type] = {'attributes' => {},
'name' => info['name'],
'required_keys' => []}
info['attributes'].each { |attr, value| hash[type]['attributes'][attr] = transform(value) }
info['required_keys'].each { |key| hash[type]['required_keys'].push(transform(key)) }
end
hash.freeze
end.freeze
end

def self.transform(value)
Expand Down

0 comments on commit 4677f2e

Please sign in to comment.