class Rackful::Serializer::JSON
Public Instance Methods
each(thing = self.resource.to_rackful) { | first ? "{\n" : ",\n" + k.to_json + ":"| ... }
click to toggle source
@yield [json] @yieldparam json [String]
# File lib/rackful/serializer.rb, line 312 def each thing = self.resource.to_rackful, &block if thing.kind_of?( Resource ) && ! thing.equal?( self.resource ) thing.serializer( self.content_type ).each( &block ) elsif thing.respond_to? :each_pair first = true thing.each_pair do |k, v| yield( ( first ? "{\n" : ",\n" ) + k.to_s.to_json + ":" ) first = false self.each v, &block end yield( first ? "{}" : "\n}" ) elsif thing.respond_to? :each first = true thing.each do |v| yield( first ? "[\n" : ",\n" ) first = false self.each v, &block end yield( first ? "[]" : "\n]" ) elsif thing.kind_of?( String ) && thing.encoding == Encoding::BINARY yield Base64.encode64(thing).chomp.to_json elsif thing.kind_of?( Time ) yield thing.utc.xmlschema.to_json else yield thing.to_json end end