Skip to content

Instantly share code, notes, and snippets.

@mnin
Last active December 13, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnin/4952990 to your computer and use it in GitHub Desktop.
Save mnin/4952990 to your computer and use it in GitHub Desktop.
monkey patch to pass some options (e.g. create :create_additions for couch_potato) to the json adapter
# config/initializers/multi_json.rb
+ MultiJson.default_options = { create_additions: true }
# lib/gem_ext/multi_json/multi_json.rb
module MultiJson
# Decode a JSON string into Ruby.
#
# <b>Options</b>
#
# <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
# <tt>:adapter</tt> :: If set, the selected engine will be used just for the call.
def load(string, options={})
+ options = default_options.merge(options)
adapter = current_adapter(options)
begin
adapter.load(string, options)
rescue adapter::ParseError => exception
raise LoadError.new(exception.message, exception.backtrace, string)
end
end
# :nodoc:
alias :decode :load
end
@flori
Copy link

flori commented Feb 14, 2013

But wouldn't this always enable create_additions, also for requests that come from untrusted web clients?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment