Sha256: aceb162a08aab5cddc338ba6ef2aae47b37a94cb0cd2304410407a47e98e05c2

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

require 'rails'
require 'active_model_serializers'

module Xing
  module Serializers

    # The base class for all Xing serializers that produce
    # Xing Hypermedia JSON resources.  In general, subclasses
    # of Xing::Serializers::Base should:
    #
    #   * Define a links method that returns a hash of hypermedia links to
    #     related resources
    #
    #   * Specify the attributes (via the ActiveModel::Serializers 'attributes'
    #     class method) that will be copied into the data: block
    #     of the generated resource.
    #
    #   * Define methods for any attributes that do not exist as plain attributes
    #     in the ActiveModel being serialized.  Note that this may (and often will) include
    #     calling other serializers on related resources or other data, in order to
    #     generate embedded resources.
    #
    # Xing serializers descend from ActiveModel::Serializer and are typically
    # instantiated with an instance of an ActiveModel model in the usual way.
    #
    class Base < ActiveModel::Serializer

      def routes
        Rails.application.routes.url_helpers
      end

      def root
        false
      end

      def as_json_with_wrap(options={})
        {
          :links => links,
          :data => as_json_without_wrap
        }
      end

      def links
        {}
      end

      alias_method_chain :as_json, :wrap
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
xing-backend-1.0.0.pre.beta lib/xing/serializers/base.rb
xing-backend-0.0.25 lib/xing/serializers/base.rb
xing-backend-0.0.23 lib/xing/serializers/base.rb
xing-backend-0.0.22 lib/xing/serializers/base.rb
xing-backend-0.0.21 lib/xing/serializers/base.rb
xing-backend-0.0.20 lib/xing/serializers/base.rb
xing-backend-0.0.19 lib/xing/serializers/base.rb
xing-backend-0.0.18 lib/xing/serializers/base.rb
xing-backend-0.0.17 lib/xing/serializers/base.rb
xing-backend-0.0.16 lib/xing/serializers/base.rb
xing-backend-0.0.15 lib/xing/serializers/base.rb
xing-backend-0.0.14 lib/xing/serializers/base.rb
xing-backend-0.0.13 lib/xing/serializers/base.rb
xing-backend-0.0.12 lib/xing/serializers/base.rb
xing-backend-0.0.11 lib/xing/serializers/base.rb
xing-backend-0.0.10 lib/xing/serializers/base.rb