Sha256: 7e93c97e90b4eb3f1dbe2ec4c5a89fdfc4ec2a19632c35e193799b109acfcb9e

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 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' ] = 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

1 entries across 1 versions & 1 rubygems

Version Path
cuba-api-0.2.0 lib/cuba_api/response_status.rb