Class: Wukong::Processor::Recordize

Inherits:
Serializer show all
Defined in:
lib/wukong/widget/serializers.rb

Overview

A widget for turning a record into an instance of some class. The class must provide a "class method" receive which accepts a Hash argument.

Constant Summary

Constants inherited from Wukong::Processor

SerializerError

Instance Method Summary collapse

Methods inherited from Serializer

#handle_error

Methods inherited from Wukong::Processor

configure, consumes, description, #expected_record_type, #expected_serialization, #finalize, #perform_action, produces, #receive_action, #setup, #stop, valid_serializer?, validate_and_set_serialization

Methods included from Logging

included

Methods included from Hanuman::StageClassMethods

#builder, #label, #register, #set_builder

Instance Method Details

#process(record) ⇒ Object

Turn the given record into an instance of the class named with the model field.

Parameters:

  • record (Hash, #to_wire)

Returns:

  • (Object)


292
293
294
295
296
297
298
# File 'lib/wukong/widget/serializers.rb', line 292

def process(record)
  wire_format = record.try(:to_wire) || record
  raise SerializerError.new("Can only recordize a Hash-like record") unless wire_format.is_a?(Hash)
  yield model.receive(wire_format)
rescue => e
  handle_error(record, e)
end