Sha256: 5cbb88217666bcb5631de96a035c81cf619cf1704a13f87d82234f837dc94a33

Contents?: true

Size: 588 Bytes

Versions: 3

Compression:

Stored size: 588 Bytes

Contents

module Rao
  module Api
    module ResourcesController::SerializationConcern
      extend ActiveSupport::Concern

      private

      def serialize_collection(collection)
        collection.collect do |resource|
          serialize_resource(resource)
        end
      end

      def serialize_resource(resource)
        json = resource.as_json
        json[:errors] = serialize_errors(resource.errors) if resource.errors.any?
        json
      end

      def serialize_errors(errors, full_messages: true)
        errors.as_json(full_messages: full_messages)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rao-api-resources_controller-0.0.52.pre app/concerns/rao/api/resources_controller/serialization_concern.rb
rao-api-resources_controller-0.0.51.pre app/concerns/rao/api/resources_controller/serialization_concern.rb
rao-api-resources_controller-0.0.50.pre app/concerns/rao/api/resources_controller/serialization_concern.rb