lib/roda/plugins/json.rb in roda-1.1.0 vs lib/roda/plugins/json.rb in roda-1.2.0

- old
+ new

@@ -34,23 +34,17 @@ # plugin :json # json_result_classes << Sequel::Model module Json # Set the classes to automatically convert to JSON def self.configure(app) - app.instance_eval do - @json_result_classes ||= [Array, Hash] - end + app.opts[:json_result_classes] ||= [Array, Hash] end module ClassMethods # The classes that should be automatically converted to json - attr_reader :json_result_classes - - # Copy the json_result_classes into the subclass - def inherited(subclass) - super - subclass.instance_variable_set(:@json_result_classes, json_result_classes.dup) + def json_result_classes + opts[:json_result_classes] end end module RequestMethods CONTENT_TYPE = 'Content-Type'.freeze @@ -61,10 +55,10 @@ # If the result is an instance of one of the json_result_classes, # convert the result to json and return it as the body, using the # application/json content-type. def block_result_body(result) case result - when *self.class.roda_class.json_result_classes + when *roda_class.json_result_classes response[CONTENT_TYPE] = APPLICATION_JSON convert_to_json(result) else super end