lib/fast_serializer/serializer.rb in fast_serializer-1.1.0 vs lib/fast_serializer/serializer.rb in fast_serializer-1.1.1

- old
+ new

@@ -56,10 +56,11 @@ # Serializing a nil object will result in nil rather than an empty hash. module Serializer def self.included(base) base.extend(ClassMethods) + base.extend(ArrayHelper) unless base.is_a?(FastSerializer::ArraySerializer) end # Return the wrapped object that is being serialized. attr_reader :object @@ -251,9 +252,17 @@ end # Define a delegate method name +attribute+ that invokes the +field+ method on the wrapped object. def define_delegate(attribute, field) define_method(attribute){ object.send(field) } + end + end + + module ArrayHelper + # Helper method to serialize an array of values using this serializer. + def array(values, options = nil) + options = (options ? options.merge(:serializer => self) : {:serializer => self}) + FastSerializer::ArraySerializer.new(values, options) end end # Create a new serializer for the specified object. #