lib/ears/middlewares/json.rb in ears-0.3.1 vs lib/ears/middlewares/json.rb in ears-0.3.2

- old
+ new

@@ -1,18 +1,25 @@ +require 'ears/middleware' require 'multi_json' module Ears module Middlewares - class JSON - attr_reader :symbolize_keys - + # A middleware that automatically parses your JSON payload. + class JSON < Middleware + # @param [Hash] opts The options for the middleware. + # @option opts [Boolean] :symbolize_keys Whether to symbolize the keys of your payload. def initialize(opts = {}) + super() @symbolize_keys = opts.fetch(:symbolize_keys, true) end def call(delivery_info, metadata, payload, app) parsed_payload = MultiJson.load(payload, symbolize_keys: symbolize_keys) app.call(delivery_info, metadata, parsed_payload) end + + private + + attr_reader :symbolize_keys end end end