Class: Wukong::Processor::ToJson
- Inherits:
-
Serializer
- Object
- Hanuman::Stage
- Wukong::Processor
- Serializer
- Wukong::Processor::ToJson
- Defined in:
- lib/wukong/widget/serializers.rb
Overview
A widget for serializing inputs to JSON.
Constant Summary
Constants inherited from Wukong::Processor
Instance Attribute Summary
Attributes included from Hanuman::StageInstanceMethods
Instance Method Summary collapse
-
#process(record) {|json| ... } ⇒ Object
Yields the input
record
serialized as JSON.
Methods inherited from Serializer
Methods inherited from Wukong::Processor
configure, description, #finalize, #perform_action, #receive_action, #setup, #stop
Methods included from Logging
Methods inherited from Hanuman::Stage
Methods included from Hanuman::StageClassMethods
#builder, #label, #register, #set_builder
Methods included from Hanuman::StageInstanceMethods
#add_link, #linkable_name, #root
Instance Method Details
#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 |