Sha256: ef405d05e9149789e8bf760b77163434dbac5639394db05689d51ebe7e4b7ddb

Contents?: true

Size: 706 Bytes

Versions: 1

Compression:

Stored size: 706 Bytes

Contents

module JsonApiClient
  module Helpers
    module Serializable
      extend ActiveSupport::Concern

      included do
        class_attribute :read_only_attributes, instance_accessor: false
        self.read_only_attributes = ['id', 'type', 'links', 'meta', 'relationships']
      end

      def serializable_hash
        attributes.slice('id', 'type').tap do |h|
          relationships.serializable_hash.tap do |r|
            h['relationships'] = r unless r.empty?
          end
          h['attributes'] = attributes_for_serialization
        end
      end

      protected

      def attributes_for_serialization
        attributes.except(*self.class.read_only_attributes)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json_api_client-1.0.0.beta5 lib/json_api_client/helpers/serializable.rb