Method: Wukong::Processor::ToJson#process
- Defined in:
- lib/wukong/widget/serializers.rb
#process(record) {|json| ... } ⇒ Object
Yields the input record
serialized as JSON.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wukong/widget/serializers.rb', line 40 def process(record) raise SerializerError.new("Cannot serialize: <nil>") if record.nil? if record.respond_to?(:to_json) && !record.is_a?(Hash) # We only want to invoke to_json if it has been explicitly defined json = record.to_json(pretty: pretty) else json = MultiJson.dump(record.try(:to_wire) || record, pretty: pretty) end yield json rescue => e handle_error(record, e) end |