lib/ixtlan/babel/factory.rb in ixtlan-babel-0.2.1 vs lib/ixtlan/babel/factory.rb in ixtlan-babel-0.3.0

- old
+ new

@@ -27,29 +27,38 @@ def initialize(custom_serializers = {}) @map = DEFAULT_MAP.dup @map.merge!(custom_serializers) end - def add(clazz, &block) - @map[clazz.to_s] = block + def add( clazz, &block ) + @map[ clazz.to_s ] = block end - def new(resource) + def new_serializer( resource ) if resource.respond_to?(:model) model = resource.model elsif resource.respond_to? :collect if resource.empty? return EmptyArraySerializer.new else r = resource.first - model = r.respond_to?(:model) ? r.model : r.class + model = r.respond_to?( :model ) ? r.model : r.class end else model = resource.class end - ser = const_retrieve("#{model}Serializer").new(resource) - ser.add_custom_serializers(@map) + ser = const_retrieve( "#{model}Serializer" ).new( resource ) + ser.add_custom_serializers( @map ) ser + end + + def new( resource ) + warn 'DEPRECATED use new_serializer instead' + new_serializer( resource ) + end + + def new_filter( clazz ) + const_retrieve( "#{clazz}Filter" ).new( clazz ) end def const_retrieve( const ) obj = Object const.split(/::/).each do |part|