Class: Unimatrix::Activist::Serializer
- Inherits:
-
Object
- Object
- Unimatrix::Activist::Serializer
- Defined in:
- lib/unimatrix/activist/serializer.rb
Instance Method Summary collapse
-
#initialize(payload = [], options = {}) ⇒ Serializer
constructor
A new instance of Serializer.
- #serialize(node, options = {}) ⇒ Object
Constructor Details
#initialize(payload = [], options = {}) ⇒ Serializer
Returns a new instance of Serializer.
5 6 7 8 |
# File 'lib/unimatrix/activist/serializer.rb', line 5 def initialize( payload = [], = {} ) @payload = [ payload ].flatten @options = end |
Instance Method Details
#serialize(node, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/unimatrix/activist/serializer.rb', line 10 def serialize( node, = {} ) result = {} result[ node ] = @payload.map do | object | node_object = {} node_object[ :type_name ] = ( object.respond_to?( :type_name ) ? object.type_name : object.class.name.gsub( /Unimatrix::Activist/, '' ).underscore ) if object.respond_to?( :fields ) object.fields.each do | name, | node_object[ name.to_sym ] = object.send( name ) end end node_object end result end |