Sha256: b3e316dfa1a5be5f9b5ffee688428147b8c63c5bb68d8a1d7710d8fa8f719847

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

module CubaApi
  module ResponseStatus
    def response_status( obj, options = {})
      if options[:response_status] != false
        if obj.respond_to?( :errors ) && obj.errors.size > 0
          res.status = 412 # Precondition Failed
          obj = obj.errors
        elsif req.post?
          res.status = 201 # Created
          if obj.respond_to?( :id ) && ! res[ 'Location' ]
            res[ 'Location' ] = env[ 'SCRIPT_NAME' ].to_s+ "/#{obj.id}"
          end
        elsif req.delete?
          res.status = 204 # No Content
          obj = ''
        end
      end
      obj
    end

    def self.included( base )
      base.prepend_aspect :response_status
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cuba-api-0.3.2 lib/cuba_api/response_status.rb
cuba-api-0.3.1 lib/cuba_api/response_status.rb
cuba-api-0.3.0 lib/cuba_api/response_status.rb