Methods enabling Database object integration with the json type.
Reset the conversion procs when extending the Database object, so it will pick up the json convertor. This is only done for the native postgres adapter.
# File lib/sequel/extensions/pg_json.rb, line 109 def self.extended(db) db.reset_conversion_procs if db.respond_to?(:reset_conversion_procs) end
Parse the given string as json, returning either a JSONArray or JSONHash instance, and raising an error if the JSON parsing does not yield an array or hash.
# File lib/sequel/extensions/pg_json.rb, line 89 def self.parse_json(s) begin value = JSON.parse(s) rescue JSON::ParserError=>e raise Sequel.convert_exception_class(e, Sequel::InvalidValue) end case value when Array JSONArray.new(value) when Hash JSONHash.new(value) else raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})" end end
Generated with the Darkfish Rdoc Generator 2.