Class: Restful::Serializers::ParamsSerializer
- Defined in:
- lib/restful/serializers/params_serializer.rb
Instance Method Summary collapse
Methods inherited from Base
#deserialize, #formatted_value, serializer, serializer_name
Instance Method Details
#serialize(resource, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/restful/serializers/params_serializer.rb', line 13 def serialize(resource, = {}) params = {} resource.values.each do |value| if value.type == :collection # serialize the stuffs resources = value.value next if resources.empty? name = resources.first.name.pluralize array = [] resources.each do |resource| array << serialize(resource) end params["#{paramify_keys(value.name)}_attributes".to_sym] = array elsif value.type == :link params[paramify_keys(value.name).to_sym] = Restful::Rails.tools.dereference(value.value) elsif value.type == :resource params["#{paramify_keys(value.name)}_attributes".to_sym] = serialize(value) else # plain ole params[paramify_keys(value.name).to_sym] = value.value # no need to format dates etc - just pass objects through. end end params end |