Sha256: 51a4db31e2a44c9f948a261b2789051a7c5a787a6be054f509928b666194f7bb

Contents?: true

Size: 735 Bytes

Versions: 14

Compression:

Stored size: 735 Bytes

Contents

module Almodovar
  class ResourcePresenter
    class JsonSerializer < Serializer
        
      def to_json
        require 'yajl'
        Yajl::Encoder.encode(as_json, :pretty => true) + "\n"
      end
      
      def as_json
        ActiveSupport::OrderedHash[:resource_type, resource.resource_type].tap do |message|
          message.merge! attributes_as_json
          message.merge! links_as_json
        end
      end
      
      private
      
      def attributes_as_json
        resource.attributes
      end

      def links_as_json
        resource.all_links.inject(ActiveSupport::OrderedHash.new) do |message, link|
          message.merge! link.as_json(options_for_link)
        end
      end
        
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
almodovar-server-0.2.0 lib/almodovar-server/resource_presenter/json_serializer.rb
almodovar-server-0.1.2 lib/almodovar-server/resource_presenter/json_serializer.rb
almodovar-server-0.1.1 lib/almodovar-server/resource_presenter/json_serializer.rb
almodovar-server-0.1.0 lib/almodovar-server/resource_presenter/json_serializer.rb
almodovar-0.9.8 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.7 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.6 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.5 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.4 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.2 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.3 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.1 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.9.0 lib/almodovar/resource_presenter/json_serializer.rb
almodovar-0.8.0 lib/almodovar/resource_presenter/json_serializer.rb