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

- old
+ new

@@ -26,18 +26,21 @@ # r.is "foo" do # {'a'=>'b'} # end # # By default, only arrays and hashes are handled, but you - # can automatically convert other types to json by adding - # them to json_result_classes: + # can specifically set the allowed classes to json by adding + # using the :classes option when loading the plugin: # - # plugin :json - # json_result_classes << Sequel::Model + # plugin :json, :classes=>[Array, Hash, Sequel::Model] module Json # Set the classes to automatically convert to JSON - def self.configure(app) - app.opts[:json_result_classes] ||= [Array, Hash] + def self.configure(app, opts={}) + classes = opts[:classes] || [Array, Hash] + app.opts[:json_result_classes] ||= [] + app.opts[:json_result_classes] += classes + app.opts[:json_result_classes].uniq! + app.opts[:json_result_classes].extend(RodaDeprecateMutation) end module ClassMethods # The classes that should be automatically converted to json def json_result_classes